r188863 - Issue fixits replacing invalid character literals with the equivalent \xNN

Stephan Bergmann sbergman at redhat.com
Wed Aug 21 11:43:07 PDT 2013


On 08/21/2013 06:18 PM, Richard Smith wrote:
> On 20 Aug 2013 21:15, "Nick Lewycky" <nicholas at mxc.ca
> <mailto:nicholas at mxc.ca>> wrote:
>  >
>  > Author: nicholas
>  > Date: Tue Aug 20 23:10:58 2013
>  > New Revision: 188863
>  >
>  > URL: http://llvm.org/viewvc/llvm-project?rev=188863&view=rev
>  > Log:
>  > Issue fixits replacing invalid character literals with the equivalent
> \xNN
>  > escape code.
>  >
>  > Added:
>  >     cfe/trunk/test/Lexer/char-literal-encoding-fixit.c
>  > Modified:
>  >     cfe/trunk/lib/Lex/LiteralSupport.cpp
>  >
>  > Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
>  > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=188863&r1=188862&r2=188863&view=diff
>  >
> ==============================================================================
>  > --- cfe/trunk/test/Lexer/char-literal-encoding-fixit.c (added)
>  > +++ cfe/trunk/test/Lexer/char-literal-encoding-fixit.c Tue Aug 20
> 23:10:58 2013
>  > @@ -0,0 +1,11 @@
>  > +// RUN: cp %s %t
>  > +// RUN: %clang_cc1 -fixit -x c %t
>  > +// RUN: FileCheck -input-file=%t %t
>  > +
>  > +// Note that this file is not valid UTF-8.
>  > +
>  > +int test1 = 'ˆ';
>  > +// CHECK: int test1 = '\x88';
>  > +
>  > +int test2 = 'abˆc';
>  > +// CHECK: int test2 = 'ab\x88c';

But the latter will be parsed as "a", "b", "\x88c" rather than "a", "b", 
"\x88", "c".  I think the only safe way to do such a replacement esp. 
for character literals is to use octal \ooo escapes.  (For string 
literals, there would also be the possibility of splitting into adjacent 
string literals.)

Stephan




More information about the cfe-commits mailing list