This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
preprocessor/8524: _Pragma within macros is improperly expanded
- From: Matthias Klose <doko at smile dot cs dot tu-berlin dot de>
- To: gcc-gnats at gcc dot gnu dot org, debian-gcc at lists dot debian dot org
- Cc: Zack Weinberg <zack at codesourcery dot com>, Neil Booth <neil at daikokuya dot co dot uk>, Andrew Suffield <asuffield at debian dot org>
- Date: Mon, 11 Nov 2002 07:30:23 +0100
- Subject: preprocessor/8524: _Pragma within macros is improperly expanded
- Reply-to: 157416 at bugs dot debian dot org, Andrew Suffield <asuffield at debian dot org>
>Number: 8524
>Category: preprocessor
>Synopsis: _Pragma within macros is improperly expanded
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Nov 10 22:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Matthias Klose
>Release: 3.2.1 2002-11-03
>Organization:
>Environment:
System: Linux smile 2.4.18-xfs #1 Tue Mar 12 22:42:02 CET 2002 i686 unknown
Architecture: i686
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
>Description:
The original report from the Debian BTS, fix applied to head and branch:
aps100@cyclone:~$ cat foo.c
_Pragma("foo"); int y;
#define FOO _Pragma("foo"); int x;
FOO
aps100@cyclone:~$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"
# 1 "foo.c"
#pragma foo
# 1 "foo.c"
; int y;
# 3 "foo.c"
#pragma ; int x;foo
The first line is expanded correctly; the third is not (rendering
_Pragma almost completely useless).
Fixed by Neil:
* cpphash.h (FIRST, LAST, CUR, RLIMIT): Fix definitions.
* cpplib.c (destringize_and_run): Kludge around getting
tokens from in-progress macros.
(_cpp_do__Pragma): Simplify. testsuite:
* gcc.dg/cpp/_Pragma4.c: New test.
Bug submitter claims:
Nope, still not right. Here's a new case where it breaks:
aps100@cyclone:~/tmp$ cat foo.c
#define ALPHA(A) alpha_ ## A
#define BETA(B) beta_ ## B
#define GAMMA(C) _Pragma("moose") ALPHA(C) BETA(C)
GAMMA(baz);
aps100@cyclone:~/tmp$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"
# 4 "foo.c"
#pragma moose=20
# 4 "foo.c"
alpha_baz beta_alpha_baz;
aps100@cyclone:~/tmp$ cpp-2.95 foo.c
# 1 "foo.c"
_Pragma("moose") alpha_baz beta_baz ;
=3D=3D
Note how beta_baz has become beta_alpha_baz in 3.2. This only happens
when the _Pragma is present, so I presume it's the same bug in another
form.
But wait! It gets better:
aps100@cyclone:~/tmp$ cat foo.c
#define ALPHA
#define BETA(B) beta_ ## B
#define GAMMA(C) _Pragma("moose") ALPHA BETA(C)
GAMMA(baz);
aps100@cyclone:~/tmp$ cpp-3.2 foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"
# 4 "foo.c"
#pragma moose=20
# 4 "foo.c"
cpp-3.2: Internal error: Aborted (program cpp0)
Please submit a full bug report.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: