r191833 - Accept #pragma warning(push, 0) without warning

Reid Kleckner reid at kleckner.net
Wed Oct 2 08:19:23 PDT 2013


Author: rnk
Date: Wed Oct  2 10:19:23 2013
New Revision: 191833

URL: http://llvm.org/viewvc/llvm-project?rev=191833&view=rev
Log:
Accept #pragma warning(push, 0) without warning

This partially addresses PR17435, but it doesn't actually implement the
pragma.  If we implement it, we should map levels 1-4 to something like
-Wall and level 0 to something like -w.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/test/Preprocessor/pragma_microsoft.c
    cfe/trunk/test/Preprocessor/pragma_microsoft.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=191833&r1=191832&r2=191833&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Wed Oct  2 10:19:23 2013
@@ -422,7 +422,7 @@ def warn_pragma_warning_spec_invalid :
           " 'error', 'once', 'suppress', 1, 2, 3, or 4">,
   InGroup<UnknownPragmas>;
 def warn_pragma_warning_push_level :
-  ExtWarn<"#pragma warning(push, level) requires a level between 1 and 4">,
+  ExtWarn<"#pragma warning(push, level) requires a level between 0 and 4">,
   InGroup<UnknownPragmas>;
 def warn_pragma_warning_expected_number :
   ExtWarn<"#pragma warning expected a warning number">,

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=191833&r1=191832&r2=191833&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Oct  2 10:19:23 2013
@@ -528,7 +528,7 @@ void PrintPPOutputPPCallbacks::PragmaWar
   startNewLineIfNeeded();
   MoveToLine(Loc);
   OS << "#pragma warning(push";
-  if (Level)
+  if (Level >= 0)
     OS << ", " << Level;
   OS << ')';
   setEmittedDirectiveOnThisLine();

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=191833&r1=191832&r2=191833&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Wed Oct  2 10:19:23 2013
@@ -1007,22 +1007,22 @@ public:
   }
 };
 
-// Returns 0 on failure.
-static unsigned LexSimpleUint(Preprocessor &PP, Token &Tok) {
+// Returns -1 on failure.
+static int LexSimpleInt(Preprocessor &PP, Token &Tok) {
   assert(Tok.is(tok::numeric_constant));
   SmallString<8> IntegerBuffer;
   bool NumberInvalid = false;
   StringRef Spelling = PP.getSpelling(Tok, IntegerBuffer, &NumberInvalid);
   if (NumberInvalid)
-    return 0;
+    return -1;
   NumericLiteralParser Literal(Spelling, Tok.getLocation(), PP);
   if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
-    return 0;
+    return -1;
   llvm::APInt APVal(32, 0);
   if (Literal.GetIntegerValue(APVal))
-    return 0;
+    return -1;
   PP.Lex(Tok);
-  return unsigned(APVal.getLimitedValue(UINT_MAX));
+  return int(APVal.getLimitedValue(INT_MAX));
 }
 
 /// "\#pragma warning(...)".  MSVC's diagnostics do not map cleanly to clang's
@@ -1055,13 +1055,13 @@ struct PragmaWarningHandler : public Pra
 
     if (II->isStr("push")) {
       // #pragma warning( push[ ,n ] )
-      unsigned Level = 0;
+      int Level = -1;
       PP.Lex(Tok);
       if (Tok.is(tok::comma)) {
         PP.Lex(Tok);
         if (Tok.is(tok::numeric_constant))
-          Level = LexSimpleUint(PP, Tok);
-        if (Level < 1 || Level > 4) {
+          Level = LexSimpleInt(PP, Tok);
+        if (Level < 0 || Level > 4) {
           PP.Diag(Tok, diag::warn_pragma_warning_push_level);
           return;
         }
@@ -1104,8 +1104,8 @@ struct PragmaWarningHandler : public Pra
         SmallVector<int, 4> Ids;
         PP.Lex(Tok);
         while (Tok.is(tok::numeric_constant)) {
-          unsigned Id = LexSimpleUint(PP, Tok);
-          if (Id == 0 || Id >= INT_MAX) {
+          int Id = LexSimpleInt(PP, Tok);
+          if (Id <= 0) {
             PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
             return;
           }

Modified: cfe/trunk/test/Preprocessor/pragma_microsoft.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_microsoft.c?rev=191833&r1=191832&r2=191833&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_microsoft.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_microsoft.c Wed Oct  2 10:19:23 2013
@@ -98,15 +98,20 @@ void g() {}
 #pragma warning(default : 321)
 #pragma warning(pop)
 
+#pragma warning(push, 0)
+// FIXME: We could probably support pushing warning level 0.
+#pragma warning(pop)
+
 #pragma warning  // expected-warning {{expected '('}}
 #pragma warning(   // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
 #pragma warning()   // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
 #pragma warning(push 4)  // expected-warning {{expected ')'}}
 #pragma warning(push  // expected-warning {{expected ')'}}
-#pragma warning(push, 5)  // expected-warning {{requires a level between 1 and 4}}
+#pragma warning(push, 5)  // expected-warning {{requires a level between 0 and 4}}
 #pragma warning(pop, 1)  // expected-warning {{expected ')'}}
 #pragma warning(push, 1) asdf // expected-warning {{extra tokens at end of #pragma warning directive}}
 #pragma warning(disable 4705) // expected-warning {{expected ':'}}
 #pragma warning(disable : 0) // expected-warning {{expected a warning number}}
 #pragma warning(default 321) // expected-warning {{expected ':'}}
 #pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}}
+#pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}}

Modified: cfe/trunk/test/Preprocessor/pragma_microsoft.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_microsoft.cpp?rev=191833&r1=191832&r2=191833&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_microsoft.cpp (original)
+++ cfe/trunk/test/Preprocessor/pragma_microsoft.cpp Wed Oct  2 10:19:23 2013
@@ -1,3 +1,3 @@
 // RUN: %clang_cc1 %s -fsyntax-only -std=c++11 -verify -fms-extensions
 
-#pragma warning(push, 4_D) // expected-warning {{requires a level between 1 and 4}}
+#pragma warning(push, 4_D) // expected-warning {{requires a level between 0 and 4}}





More information about the cfe-commits mailing list