[cfe-commits] r159226 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/PPDirectives.cpp test/Preprocessor/line-directive.c
Fariborz Jahanian
fjahanian at apple.com
Tue Jun 26 14:19:20 PDT 2012
Author: fjahanian
Date: Tue Jun 26 16:19:20 2012
New Revision: 159226
URL: http://llvm.org/viewvc/llvm-project?rev=159226&view=rev
Log:
preprocessing: gcc supports #line 0. So, treat this
as a gcc supported extension with usual treatment
with -pedantic (warn) and -pedantic-errors (error).
// rdar://11550996
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Preprocessor/line-directive.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=159226&r1=159225&r2=159226&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Jun 26 16:19:20 2012
@@ -415,6 +415,9 @@
"floating point literal in preprocessor expression">;
def err_pp_line_requires_integer : Error<
"#line directive requires a positive integer argument">;
+def ext_pp_line_zero : Extension<
+ "#line directive with zero argument is a GNU extension">,
+ InGroup<GNU>;
def err_pp_line_invalid_filename : Error<
"invalid filename for #line directive">;
def warn_pp_line_decimal : Warning<
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=159226&r1=159225&r2=159226&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jun 26 16:19:20 2012
@@ -804,14 +804,7 @@
Val = NextVal;
}
- // Reject 0, this is needed both by #line numbers and flags.
- if (Val == 0) {
- PP.Diag(DigitTok, DiagID);
- PP.DiscardUntilEndOfDirective();
- return true;
- }
-
- if (DigitTokBegin[0] == '0')
+ if (DigitTokBegin[0] == '0' && Val)
PP.Diag(DigitTok.getLocation(), diag::warn_pp_line_decimal);
return false;
@@ -834,6 +827,9 @@
unsigned LineNo;
if (GetLineValue(DigitTok, LineNo, diag::err_pp_line_requires_integer,*this))
return;
+
+ if (LineNo == 0)
+ Diag(DigitTok, diag::ext_pp_line_zero);
// Enforce C99 6.10.4p3: "The digit sequence shall not specify ... a
// number greater than 2147483647". C90 requires that the line # be <= 32767.
Modified: cfe/trunk/test/Preprocessor/line-directive.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=159226&r1=159225&r2=159226&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/line-directive.c (original)
+++ cfe/trunk/test/Preprocessor/line-directive.c Tue Jun 26 16:19:20 2012
@@ -3,8 +3,8 @@
// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF'
#line 'a' // expected-error {{#line directive requires a positive integer argument}}
-#line 0 // expected-error {{#line directive requires a positive integer argument}}
-#line 00 // expected-error {{#line directive requires a positive integer argument}}
+#line 0 // expected-warning {{#line directive with zero argument is a GNU extension}}
+#line 00 // expected-warning {{#line directive with zero argument is a GNU extension}}
#line 2147483648 // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
#line 42 // ok
#line 42 'a' // expected-error {{invalid filename for #line directive}}
@@ -88,5 +88,8 @@
_\
_LINE__ == 42 ? 1: -1]; /* line marker is location of first _ */
+// rdar://11550996
+#line 0 "line-directive.c" // expected-warning {{#line directive with zero argument is a GNU extension}}
+undefined t; // expected-error {{unknown type name 'undefined'}}
More information about the cfe-commits
mailing list