<< Back to previous view

[PCC-403] #if conditional leaks some information Created: 25/Aug/12  Updated: 15/Sep/12

Status: Closed
Project: pcc
Component/s: C preprocessor
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Iain Hibbert Assignee: Unassigned
Resolution: Fixed Votes: 0
Environment: NetBSD/i386


 Description   
The #if conditional is leaking some information when the test is expanded from a macro, which carries over to affect the next conditional

the following code demonstrates the issue

#define VAL 5
#define FOO defined(VAL)
#define BAR defined(FOOBAR)

#if FOO
foo: FOO
#endif

#if BAR
bar: BAR
#endif

when compiled with pcc -E, produces (without blank lines)

foo: defined(5)
bar: defined(FOOBAR)

which is clearly wrong.. but if the code is changed to

#if TEST
test: TEST
#endif

#if BAR
bar: BAR
#endif

then it works ok..



 Comments   
Comment by Anders Magnusson [ 30/Aug/12 05:59 PM ]
Hm, 6.10.1 clause 3 says:

" If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. "

So, using defined here enters the "undefined" area...?
Comment by Iain Hibbert [ 01/Sep/12 10:36 AM ]
I have emailed the author of the upstream code that was using this construct (IPF, in the NetBSD sources), will work on it separately..
Comment by Iain Hibbert [ 15/Sep/12 07:13 PM ]
I have fixed this in the upstream code so it is no longer an issue
Generated at Mon Sep 22 12:14:15 CEST 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.