Compiling or preprocessing a file that ends immediately after _Pragma leads to an ICE: <bug.c>:1:1: error: _Pragma takes a parenthesized string literal <built-in>:0: internal compiler error: Segmentation fault Simply `echo _Pragma | cpp` is enough to show it. I'm using gcc 4.1.1.
Confirmed, with svn head and the FC6 gcc 4.1.
Created attachment 13372 [details] patch to fix part of the bug This patch seems to fix the preprocessor side of the bug. However there are problems later in the C parser.
Created attachment 13373 [details] patch to fix the bug By fixing the preprocessor part better, we can fix the bug completely. However, I don't have time now to prepare a proper patch (and test it properly).
I'm testing this patch.
A program like '_Pragma /*comment*/' still gives an ICE. I'm testing an updated patch.
What does a plain "_Pragma" mean? Currently we try to give an error for this. However, it is not clear that this is actually erroneous. The copy of the standard that I am reading only mentions: A unary operator expression of the form: _Pragma ( string-literal ) ... but a plain _Pragma does not have that form. I'm not even sure that _Pragma(something-other-than-string-literal) should be recognized (but I'm new to C standardese...) Perhaps I have the wrong version of the standard or perhaps there is some more recent development of which I'm unaware. Anyway if we assume that a plain _Pragma is not an error then the first patch here is close to the correct one -- it just returns the plain _Pragma to the FE as an identifier. If all forms other than the full form are unrecognized then I think this first patch is correct.
FYI -- I talked to Neil and he was of the opinion that non-matching _Pragma forms were undefined. So, I think it is best if GCC chooses to continue giving an error in these situations.
Subject: Bug 30786 Author: tromey Date: Wed Oct 31 14:50:13 2007 New Revision: 129800 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129800 Log: gcc/testsuite PR preprocessor/30786: * gcc.dg/cpp/pr30786.c: New file. libcpp PR preprocessor/30786: * macro.c (builtin_macro): Return result of _cpp_do__Pragma. * directives.c (_cpp_do__Pragma): Return error status. * internal.h (_cpp_do__Pragma): Update. * directives.c (get__Pragma_string): Back up if EOF seen. Added: trunk/gcc/testsuite/gcc.dg/cpp/pr30786.c Modified: trunk/gcc/testsuite/ChangeLog trunk/libcpp/ChangeLog trunk/libcpp/directives.c trunk/libcpp/internal.h trunk/libcpp/macro.c
Fixed on the trunk.
Closing 4.1 branch.
Closing 4.2 branch, fixed in 4.3.