diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-16 23:44:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-16 23:44:05 +0000 |
commit | 1c6c64b5181a960c7d4cace4995a938d4dfa6fbf (patch) | |
tree | 4fa5f1c739ab90a8768ae554889b26360f4ee872 | |
parent | 2b334bb3126a67895813e49e6228dad4aec0b4d6 (diff) |
emit warn_char_constant_too_large at most once per literal, fixing PR6852
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101580 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/LiteralSupport.cpp | 5 | ||||
-rw-r--r-- | test/Preprocessor/if_warning.c | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 1cfa0e3745..f425582264 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -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; } } diff --git a/test/Preprocessor/if_warning.c b/test/Preprocessor/if_warning.c index 98653a8fee..345ac95eb4 100644 --- a/test/Preprocessor/if_warning.c +++ b/test/Preprocessor/if_warning.c @@ -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 |