diff options
author | Craig Topper <craig.topper@gmail.com> | 2011-08-19 03:20:12 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2011-08-19 03:20:12 +0000 |
commit | 6eb2058a6a25f49a12fa0cda6f8589bdbc8788dd (patch) | |
tree | 2fa27761eeb39c0697f444fb06297b9fe9db3f83 /clang/lib/Lex/LiteralSupport.cpp | |
parent | 4dd3e948ef81134b545ffc9e416b8410507cfb60 (diff) | |
download | bcm5719-llvm-6eb2058a6a25f49a12fa0cda6f8589bdbc8788dd.tar.gz bcm5719-llvm-6eb2058a6a25f49a12fa0cda6f8589bdbc8788dd.zip |
Warn about and truncate UCNs that are too big for their character literal type.
llvm-svn: 138031
Diffstat (limited to 'clang/lib/Lex/LiteralSupport.cpp')
-rw-r--r-- | clang/lib/Lex/LiteralSupport.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 20479199c43..b82dbd863bf 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -786,6 +786,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, if (begin[0] != '\\') // If this is a normal character, consume it. ResultChar = *begin++; else { // Otherwise, this is an escape character. + unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo()); // Check for UCN. if (begin[1] == 'u' || begin[1] == 'U') { uint32_t utf32 = 0; @@ -796,9 +797,12 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, HadError = 1; } ResultChar = utf32; + if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) { + PP.Diag(Loc, diag::warn_ucn_escape_too_large); + ResultChar &= ~0U >> (32-CharWidth); + } } else { // Otherwise, this is a non-UCN escape character. Process it. - unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo()); ResultChar = ProcessCharEscape(begin, end, HadError, FullSourceLoc(Loc,PP.getSourceManager()), CharWidth, &PP.getDiagnostics()); @@ -843,10 +847,6 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, // Transfer the value from APInt to uint64_t Value = LitVal.getZExtValue(); - if (((isWide() && PP.getLangOptions().ShortWChar) || isUTF16()) && - Value > 0xFFFF) - PP.Diag(Loc, diag::warn_ucn_escape_too_large); - // If this is a single narrow character, sign extend it (e.g. '\xFF' is "-1") // if 'char' is signed for this target (C99 6.4.4.4p10). Note that multiple // character constants are not sign extended in the this implementation: |