[cfe-commits] Unknown hex escapes problem

Ted Kremenek kremenek at apple.com
Thu Dec 2 16:13:50 PST 2010


Hi Paul,

Great catch.  I've applied your change here:

  http://llvm.org/viewvc/llvm-project?view=rev&revision=120759

I believe adjusting the caret requires updating 'Loc' with the appropriate character offset within the literal.

On Dec 2, 2010, at 7:07 AM, Paul Curtis wrote:

> Hi,
> 	
> Given:
> 
> const char *format = "abc \m def";
> 
> clang generates:
> 
>> clang -fsyntax-only foo1.c
> foo1.c(1) :  warning: unknown escape sequence '\x6D'
> const char *format = "abc \m def";
>                     ^
> 
> There are a couple of problems here. Firstly, the error should clearly show
> \m not \x6D and ProcessCharEscape makes a valiant attempt:
> 
>    if (isgraph(ThisTokBuf[0]))
>      Diags->Report(Loc, diag::ext_unknown_escape)
>        << std::string()+(char)ResultChar;
>    else
>      Diags->Report(Loc, diag::ext_unknown_escape)
>        << "x"+llvm::utohexstr(ResultChar);
> 
> Unfortunately, by the time we're in the handling case, ThisTokBuf[0] has
> stepped past the invalid escape and moved to the next character, and as
> witness you get a slightly different error with this source:
> 
>> clang -fsyntax-only foo1.c
> foo1.c(1) :  warning: unknown escape sequence '\m'
> const char *format = "abc \mx def";
> 
> Now, this is correct.  What ProcessCharEscape should be doing is this:
> 
>    if (isgraph(ResultChar))
>      Diags->Report(Loc, diag::ext_unknown_escape)
>        << std::string()+(char)ResultChar;
>    else
>      Diags->Report(Loc, diag::ext_unknown_escape)
>        << "x"+llvm::utohexstr(ResultChar);
> 
> However the location of the caret is incorrect; perhaps I'll deal with that
> next.
> 
> --
> Paul Curtis, Rowley Associates Ltd   http://www.rowley.co.uk
> SolderCore arriving Winter 2010!   http://www.soldercore.com
> 
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list