forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dead code spotted in RELEASE build but not CHECKMATE build!

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Thu Oct 18, 2007 9:50 am    Post subject: Dead code spotted in RELEASE build but not CHECKMATE build! Reply with quote

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
View user's profile Send private message Send e-mail
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Wed Oct 24, 2007 4:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Wed Oct 24, 2007 4:55 pm    Post subject: Reply with quote

Andy

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

Paul
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Fri Oct 26, 2007 7:29 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Tue Oct 30, 2007 12:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group