]> granicus.if.org Git - clang/commitdiff
emit warn_char_constant_too_large at most once per literal, fixing PR6852
authorChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 23:44:05 +0000 (23:44 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 23:44:05 +0000 (23:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101580 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/LiteralSupport.cpp
test/Preprocessor/if_warning.c

index 1cfa0e374506fd02b5307708f2cac06f69e80be4..f4255822641ddd114df9cd07fa4f93dfa51758ee 100644 (file)
@@ -654,6 +654,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
   llvm::APInt LitVal(PP.getTargetInfo().getIntWidth(), 0);
 
   unsigned NumCharsSoFar = 0;
+  bool Warned = false;
   while (begin[0] != '\'') {
     uint64_t ResultChar;
     if (begin[0] != '\\')     // If this is a normal character, consume it.
@@ -670,8 +671,10 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
       } else {
         // Narrow character literals act as though their value is concatenated
         // in this implementation, but warn on overflow.
-        if (LitVal.countLeadingZeros() < 8)
+        if (LitVal.countLeadingZeros() < 8 && !Warned) {
           PP.Diag(Loc, diag::warn_char_constant_too_large);
+          Warned = true;
+        }
         LitVal <<= 8;
       }
     }
index 98653a8feef6dc018da3bf651272da669b1834be..345ac95eb4ba8765bbffd3042b827e8b30db9b13 100644 (file)
@@ -19,3 +19,9 @@ extern int x;
 #else 1       // Should not warn due to C99 6.10p4
 #endif
 #endif
+
+
+// PR6852
+#if 'somesillylongthing'  // expected-warning {{character constant too long for its type}} \
+                          // expected-warning {{multi-character character constant}}
+#endif