Issue Details (XML | Word | Printable)

Key: PCC-359
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Iain Hibbert
Reporter: Iain Hibbert
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

cpp does not leave comments in expanded macros, even with -CC

Created: 22/Jun/11 09:29 PM   Updated: 26/Sep/12 08:32 PM
Component/s: C preprocessor
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. File diff2 (0.5 kB)

Environment:
NetBSD/i386


 Description  « Hide
comments are discarded inside macro expansions, even when -CC is
passed to the preprocessor (or front-end), this is important for use with
lint which likes to take note of comments such as in the following macro

#define macro(x) do { foo(x); } while (/*CONSTCOND*/0)

in order to disable warnings about constant conditionals..

"gcc -C" retains comments except in macro expansions
"gcc -CC" retains all comments

I marked this as Minor, since in the context of a C compiler this is not
an essential feature, but lint is a useful tool especially so for pcc which
does not contain as much code analysis as some other compilers

 All   Comments   Change History      Sort Order: Descending order - Click to sort in ascending order
Iain Hibbert added a comment - 26/Sep/12 08:32 PM
have extended my previous fix, to solve the extended issue

Iain Hibbert added a comment - 08/Aug/12 08:29 PM
I reopen this as I found another instance where it does not work but no time to look into it at present

#define foo(a) (111 /*LINTED*/ a 111)
#define bar(a) (222 a /*LINTED*/ 222)

foo(FIRST);
bar(SECOND);
foo(bar(THIRD));
bar(foo(FOURTH));

with "pcc -E -Wp,-CC" produces

(111 /*LINTED*/ FIRST 111);
(222 SECOND /*LINTED*/ 222);
(111 /*LINTED*/ (222 THIRD 222) 111);
(222 (111 FOURTH 111) /*LINTED*/ 222);

and with "gcc -E -Wp,-CC" produces

(111 /*LINTED*/ FIRST 111);
(222 SECOND /*LINTED*/ 222);
(111 /*LINTED*/ (222 THIRD /*LINTED*/ 222) 111);
(222 (111 /*LINTED*/ FOURTH 111) /*LINTED*/ 222);

so note, that pcc does not provide the comment expanding the nested macro for some reason.. this does cause a further problem with lint when the /*LINTED*/ comment is lost, sigh..

Iain Hibbert added a comment - 27/Jul/11 05:13 PM
ragge says my fix is correct, and I have applied it

Iain Hibbert added a comment - 09/Jul/11 10:51 AM
Actually that was not sufficient as I found another failure relating to
loss of /* CONSTCOND */ from a plain macro, shown by

#define BAZ do { _foo_(); } while (/* CONSTCOND */0)
BAZ;

the diff2 attached places the readmac ++/-- into insblock(), so that
comments are kept (as appropriate) during macro expansions.. with
that, my build script completes all of src/lib with MKLINT=yes

Iain Hibbert added a comment - 08/Jul/11 10:49 PM
I thought about this some more because I surely recalled a previous issue which
referenced comments inside macros.. and I found that if I make a macro that
references that macro:

#define foo(x) do { _foo_ ## x (); } while (/* CONSTCOND */0)
#define bar foo(Y)

foo(X);
bar;

then cpp outputs

do { _foo_X (); } while (0);
do { _foo_Y (); } while (/* CONSTCOND */0);

.. which is kind of kooky

I tracked this down to the insblock() function which attempts to process CMNT from sloscan(),
but in fact if readmac == 0 then this is never returned.. applying the attached patch seems to
fix it (and make lint in src/lib/libc proceeds to completion), but I'm not sure if the readmac++/--
ought to be inside the insblock() function so that it is always covered, or if that (or this) would
cause some other side effect..