r179139 - Improve the diagnostics of the number-reading preprocessor directives.

Michael Ilseman milseman at apple.com
Tue Apr 9 18:04:18 PDT 2013


Author: milseman
Date: Tue Apr  9 20:04:18 2013
New Revision: 179139

URL: http://llvm.org/viewvc/llvm-project?rev=179139&view=rev
Log:
Improve the diagnostics of the number-reading preprocessor directives.

The GNU line marker directive was sharing code with the #line directive, but some of the warnings/errors were reporting as #line directive diagnostics in both cases.

Previously:
#line 11foo1   ==> "#line directive requires a simple digit sequence"
# 11foo1       ==> "#line directive requires a simple digit sequence"

Now, we get:
#line 11foo1   ==> "#line directive requires a simple digit sequence"
# 11foo1       ==> "GNU line marker directive requires a simple digit sequence"



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=179139&r1=179138&r2=179139&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Apr  9 20:04:18 2013
@@ -476,9 +476,9 @@ def ext_pp_line_zero : Extension<
 def err_pp_line_invalid_filename : Error<
   "invalid filename for #line directive">;
 def warn_pp_line_decimal : Warning<
-  "#line directive interprets number as decimal, not octal">;
+  "%select{#line|GNU line marker}0 directive interprets number as decimal, not octal">;
 def err_pp_line_digit_sequence : Error<
-  "#line directive requires a simple digit sequence">;
+  "%select{#line|GNU line marker}0 directive requires a simple digit sequence">;
 def err_pp_linemarker_requires_integer : Error<
   "line marker directive requires a positive integer argument">;
 def err_pp_linemarker_invalid_filename : Error<

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=179139&r1=179138&r2=179139&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Apr  9 20:04:18 2013
@@ -793,7 +793,8 @@ void Preprocessor::HandleDirective(Token
 /// GetLineValue - Convert a numeric token into an unsigned value, emitting
 /// Diagnostic DiagID if it is invalid, and returning the value in Val.
 static bool GetLineValue(Token &DigitTok, unsigned &Val,
-                         unsigned DiagID, Preprocessor &PP) {
+                         unsigned DiagID, Preprocessor &PP,
+                         bool IsGNULineDirective=false) {
   if (DigitTok.isNot(tok::numeric_constant)) {
     PP.Diag(DigitTok, DiagID);
 
@@ -817,7 +818,7 @@ static bool GetLineValue(Token &DigitTok
   for (unsigned i = 0; i != ActualLength; ++i) {
     if (!isDigit(DigitTokBegin[i])) {
       PP.Diag(PP.AdvanceToTokenCharacter(DigitTok.getLocation(), i),
-              diag::err_pp_line_digit_sequence);
+              diag::err_pp_line_digit_sequence) << IsGNULineDirective;
       PP.DiscardUntilEndOfDirective();
       return true;
     }
@@ -832,7 +833,8 @@ static bool GetLineValue(Token &DigitTok
   }
 
   if (DigitTokBegin[0] == '0' && Val)
-    PP.Diag(DigitTok.getLocation(), diag::warn_pp_line_decimal);
+    PP.Diag(DigitTok.getLocation(), diag::warn_pp_line_decimal)
+      << IsGNULineDirective;
 
   return false;
 }
@@ -998,7 +1000,7 @@ void Preprocessor::HandleDigitDirective(
   // line # limit other than it fit in 32-bits.
   unsigned LineNo;
   if (GetLineValue(DigitTok, LineNo, diag::err_pp_linemarker_requires_integer,
-                   *this))
+                   *this, true))
     return;
 
   Token StrTok;

Modified: cfe/trunk/test/Preprocessor/line-directive.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=179139&r1=179138&r2=179139&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/line-directive.c (original)
+++ cfe/trunk/test/Preprocessor/line-directive.c Tue Apr  9 20:04:18 2013
@@ -29,7 +29,7 @@
 # 42 "foo" 3 1   // expected-error {{invalid flag line marker directive}}
 # 42 "foo" 42    // expected-error {{invalid flag line marker directive}}
 # 42 "foo" 1 2   // expected-error {{invalid flag line marker directive}}
-
+# 42a33          // expected-error {{GNU line marker directive requires a simple digit sequence}}
 
 // These are checked by the RUN line.
 #line 92 "blonk.c"
@@ -83,6 +83,7 @@ typedef int q;  // original definition i
 // Line markers are digit strings interpreted as decimal numbers, this is
 // 10, not 8.
 #line 010  // expected-warning {{#line directive interprets number as decimal, not octal}}
+# 010      // expected-warning {{GNU line marker directive interprets number as decimal, not octal}}
 extern int array[__LINE__ == 10 ? 1:-1];
 
 /* PR3917 */





More information about the cfe-commits mailing list