<< 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

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

#if BAR
bar: BAR

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

#if BAR
bar: BAR

then it works ok..

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 Thu May 24 00:24:18 CEST 2018 using JIRA Enterprise Edition, Version: 3.13.1-#333.