View previous topic :: View next topic |
Author |
Message |
sparge
Joined: 11 Apr 2005 Posts: 371
|
Posted: Thu Oct 18, 2007 9:50 am Post subject: Dead code spotted in RELEASE build but not CHECKMATE build! |
|
|
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. |
|
Back to top |
|
|
sparge
Joined: 11 Apr 2005 Posts: 371
|
Posted: Wed Oct 24, 2007 4:05 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Wed Oct 24, 2007 4:55 pm Post subject: |
|
|
Andy
I have seen your post but it may be a while before I can investigate its implications.
Paul |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Fri Oct 26, 2007 7:29 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
sparge
Joined: 11 Apr 2005 Posts: 371
|
Posted: Tue Oct 30, 2007 12:24 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
|