diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2013-08-21 04:10:58 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2013-08-21 04:10:58 +0000 |
commit | 6347a8af824d8cb4197ec1a1d011f731390a8f31 (patch) | |
tree | 8df644dbd195d7c0b4d72073d09c5070e182c419 /lib/Lex/LiteralSupport.cpp | |
parent | 9b9a5bf53edc724574593bbedcb55eca0d9995c6 (diff) | |
download | clang-6347a8af824d8cb4197ec1a1d011f731390a8f31.tar.gz clang-6347a8af824d8cb4197ec1a1d011f731390a8f31.tar.bz2 clang-6347a8af824d8cb4197ec1a1d011f731390a8f31.tar.xz |
Issue fixits replacing invalid character literals with the equivalent \xNN
escape code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188863 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/LiteralSupport.cpp')
-rw-r--r-- | lib/Lex/LiteralSupport.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 08d6c438d3..2301aaed82 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -978,7 +978,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, uint32_t largest_character_for_kind; if (tok::wide_char_constant == Kind) { largest_character_for_kind = - 0xFFFFFFFFu >> (32-PP.getTargetInfo().getWCharWidth()); + 0xFFFFFFFFu >> (32 - PP.getTargetInfo().getWCharWidth()); } else if (tok::utf16_char_constant == Kind) { largest_character_for_kind = 0xFFFF; } else if (tok::utf32_char_constant == Kind) { @@ -1009,7 +1009,13 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, unsigned Msg = diag::err_bad_character_encoding; if (NoErrorOnBadEncoding) Msg = diag::warn_bad_character_encoding; - PP.Diag(Loc, Msg); + std::string escaped = llvm::utohexstr(static_cast<uint8_t>(*start)); + FullSourceLoc SourceLoc(Loc, PP.getSourceManager()); + PP.Diag(Loc, Msg) << FixItHint::CreateReplacement( + MakeCharSourceRange(PP.getLangOpts(), + SourceLoc, TokBegin, start, + start + 1), + "\\x" + escaped); if (NoErrorOnBadEncoding) { start = tmp_in_start; buffer_begin = tmp_out_start; @@ -1047,7 +1053,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo()); uint64_t result = ProcessCharEscape(TokBegin, begin, end, HadError, - FullSourceLoc(Loc,PP.getSourceManager()), + FullSourceLoc(Loc, PP.getSourceManager()), CharWidth, &PP.getDiagnostics(), PP.getLangOpts()); *buffer_begin++ = result; } |