Silverfrost Forums

Welcome to our forums

Dead code spotted in RELEASE build but not CHECKMATE build!

18 Oct 2007 8:50 #2372

I don't suppose this could be called a compiler bug; more a blind spot. The following code is a heavily-stripped down version of a routine I was hacking around yesterday.

  program unspotted_no_op
  integer trys, dsa, numdsa
  logical test (4)
  numdsa = 10
  test = .true. 
  outer_loop: do dsa = 1, numdsa
    trys = 0
    inner_loop: do
      trys = trys + 1
      if (test (1)) then
        if (test (2)) cycle outer_loop
        if (test (3)) cycle inner_loop
        exit outer_loop
      end if
    end do inner_loop          
    if (test (4)) exit outer_loop
  end do outer_loop
  stop
  end program unspotted_no_op

When compiled with /RELEASE, FTN95 correctly issues:

  warning 133 - This statement will never be executed

in respect of the line:

  if (test (4)) exit outer_loop

When compiled with /DEBUG or /CHECKMATE, however, FTN95 fails to spot that anything is or amiss (or fails to mention the fact).

I'm glad I investigated this because my first thought was that the RELEASE build was issuing a false positive. In fact, it was quite correct in identifying something that was definitely not the design intent, and which I'd never have spotted in the original code.

24 Oct 2007 3:05 #2373

Looks like I need to ask an explicit question!

Am I right in thinking as follows:

  • there is no *requirement *for a compiler to identify dead code
  • nonetheless, if a compiler elects to try and do so, build-dependent ability to do so is not the design intent, and could usefully be investigated

Having pondered this further, I've realised that dead code *per se *is not the issue; the real issue is the potentially infinite loop that dead code signals. Right?

Andy

24 Oct 2007 3:55 #2374

Andy

I have seen your post but it may be a while before I can investigate its implications.

Paul

26 Oct 2007 6:29 #2383

Andy

We have now fixed this problem for the next release.

Yes, I think you are right in what you say.

I was quite impressed that FTN95 was able to give a warning even though it only only showed up in release mode. Debug mode required a slightly different route through the compiler because do loops have to be handled in a different way.

30 Oct 2007 11:24 #2389

I was *very *impressed! I hope I didn't give any impression to the contrary - not my intention at all. The more I think about how a compiler might possibly figure out that a given line can't be got to in any possible runtime scenario, the more impressed I am. I was just surprised that the warning came in RELEASE mode rather than CHECKMATE, which is where I would have expected it.

Please login to reply.