From 540f9ae1023bba27052c742cd92d0b32361b28eb Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 26 Jun 2012 21:19:20 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159226 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticLexKinds.td | 3 +++ lib/Lex/PPDirectives.cpp | 12 ++++-------- test/Preprocessor/line-directive.c | 7 +++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 2e8e9c5005..464699fb91 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -415,6 +415,9 @@ def err_pp_illegal_floating_literal : Error< "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; def err_pp_line_invalid_filename : Error< "invalid filename for #line directive">; def warn_pp_line_decimal : Warning< diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 815c47494b..a6b7b52624 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -804,14 +804,7 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, 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 @@ void Preprocessor::HandleLineDirective(Token &Tok) { 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. diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 28e93029a5..da3c53368f 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -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 @@ extern char array2[\ _\ _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'}} -- 2.40.0