Bug 30786 - [4.2 Regression] ICE on _Pragma at end of file
Summary: [4.2 Regression] ICE on _Pragma at end of file
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.1.1
: P2 minor
Target Milestone: 4.3.0
Assignee: Tom Tromey
URL:
Keywords: error-recovery, ice-on-invalid-code, monitored
Depends on:
Blocks:
 
Reported: 2007-02-13 14:23 UTC by Harald van Dijk
Modified: 2009-03-30 21:33 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 4.3.0
Known to fail: 3.4.0 4.0.3 4.1.0 4.2.0 4.2.5
Last reconfirmed: 2007-08-19 16:13:10


Attachments
patch to fix part of the bug (677 bytes, patch)
2007-04-16 20:11 UTC, Paolo Bonzini
Details | Diff
patch to fix the bug (388 bytes, patch)
2007-04-16 20:24 UTC, Paolo Bonzini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Harald van Dijk 2007-02-13 14:23:41 UTC
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.
Comment 1 Tom Tromey 2007-02-13 15:55:12 UTC
Confirmed, with svn head and the FC6 gcc 4.1.
Comment 2 Paolo Bonzini 2007-04-16 20:11:01 UTC
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.
Comment 3 Paolo Bonzini 2007-04-16 20:24:33 UTC
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).
Comment 4 Tom Tromey 2007-08-19 16:13:09 UTC
I'm testing this patch.
Comment 5 Tom Tromey 2007-08-19 18:19:01 UTC
A program like '_Pragma /*comment*/' still gives an ICE.
I'm testing an updated patch.
Comment 6 Tom Tromey 2007-08-19 18:54:28 UTC
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.
Comment 7 Tom Tromey 2007-08-25 18:42:29 UTC
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.
Comment 8 Tom Tromey 2007-10-31 14:50:25 UTC
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

Comment 9 Jakub Jelinek 2007-11-01 18:28:19 UTC
Fixed on the trunk.
Comment 10 Joseph S. Myers 2008-07-04 21:56:37 UTC
Closing 4.1 branch.
Comment 11 Joseph S. Myers 2009-03-30 21:33:19 UTC
Closing 4.2 branch, fixed in 4.3.