<div dir="ltr">On 21 August 2013 09:18, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><p dir="ltr"><br>
On 20 Aug 2013 21:15, "Nick Lewycky" <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>> wrote:<br>
><br>
> Author: nicholas<br>
> Date: Tue Aug 20 23:10:58 2013<br>
> New Revision: 188863<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=188863&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=188863&view=rev</a><br>
> Log:<br>
> Issue fixits replacing invalid character literals with the equivalent \xNN<br>
> escape code.<br>
><br>
> Added:<br>
>     cfe/trunk/test/Lexer/char-literal-encoding-fixit.c<br>
> Modified:<br>
>     cfe/trunk/lib/Lex/LiteralSupport.cpp<br>
><br>
> Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=188863&r1=188862&r2=188863&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=188863&r1=188862&r2=188863&view=diff</a><br>



> ==============================================================================<br>
> --- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/LiteralSupport.cpp Tue Aug 20 23:10:58 2013<br>
> @@ -978,7 +978,7 @@ CharLiteralParser::CharLiteralParser(con<br>
>    uint32_t largest_character_for_kind;<br>
>    if (tok::wide_char_constant == Kind) {<br>
>      largest_character_for_kind =<br>
> -        0xFFFFFFFFu >> (32-PP.getTargetInfo().getWCharWidth());<br>
> +        0xFFFFFFFFu >> (32 - PP.getTargetInfo().getWCharWidth());<br>
>    } else if (tok::utf16_char_constant == Kind) {<br>
>      largest_character_for_kind = 0xFFFF;<br>
>    } else if (tok::utf32_char_constant == Kind) {<br>
> @@ -1009,7 +1009,13 @@ CharLiteralParser::CharLiteralParser(con<br>
>          unsigned Msg = diag::err_bad_character_encoding;<br>
>          if (NoErrorOnBadEncoding)<br>
>            Msg = diag::warn_bad_character_encoding;<br>
> -        PP.Diag(Loc, Msg);<br>
> +        std::string escaped = llvm::utohexstr(static_cast<uint8_t>(*start));</p>
</div></div><p dir="ltr">Are we guaranteed that the character is >= 0x10 here? (utohexstr might otherwise produce only one character).</p></blockquote><div>Good catch. I tried every value from <= 0x0F and we don't emit this warning in those cases. 0x0d aka. \r and 0x00 do interesting things, but otherwise should we be warning on those?<br>

</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><p dir="ltr">> +        FullSourceLoc SourceLoc(Loc, PP.getSourceManager());<br>


> +        PP.Diag(Loc, Msg) << FixItHint::CreateReplacement(<br>
> +                                 MakeCharSourceRange(PP.getLangOpts(),<br>
> +                                                     SourceLoc, TokBegin, start,<br>
> +                                                     start + 1),<br>
> +                                 "\\x" + escaped);<br>
>          if (NoErrorOnBadEncoding) {<br>
>            start = tmp_in_start;<br>
>            buffer_begin = tmp_out_start;<br>
> @@ -1047,7 +1053,7 @@ CharLiteralParser::CharLiteralParser(con<br>
>      unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo());<br>
>      uint64_t result =<br>
>        ProcessCharEscape(TokBegin, begin, end, HadError,<br>
> -                        FullSourceLoc(Loc,PP.getSourceManager()),<br>
> +                        FullSourceLoc(Loc, PP.getSourceManager()),<br>
>                          CharWidth, &PP.getDiagnostics(), PP.getLangOpts());<br>
>      *buffer_begin++ = result;<br>
>    }<br>
><br>
> Added: cfe/trunk/test/Lexer/char-literal-encoding-fixit.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/char-literal-encoding-fixit.c?rev=188863&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/char-literal-encoding-fixit.c?rev=188863&view=auto</a><br>



> ==============================================================================<br>
> --- cfe/trunk/test/Lexer/char-literal-encoding-fixit.c (added)<br>
> +++ cfe/trunk/test/Lexer/char-literal-encoding-fixit.c Tue Aug 20 23:10:58 2013<br>
> @@ -0,0 +1,11 @@<br>
> +// RUN: cp %s %t<br>
> +// RUN: %clang_cc1 -fixit -x c %t<br>
> +// RUN: FileCheck -input-file=%t %t<br>
> +<br>
> +// Note that this file is not valid UTF-8.<br>
> +<br>
> +int test1 = 'ˆ';<br>
> +// CHECK: int test1 = '\x88';<br>
> +<br>
> +int test2 = 'abˆc';<br>
> +// CHECK: int test2 = 'ab\x88c';<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</p>
</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>