[cfe-commits] proposed fix to bug Bug 7910

Eitan Adler lists at eitanadler.com
Mon Jan 16 19:54:11 PST 2012


I was asked to resend with an attached patch instead

On Mon, Jan 16, 2012 at 10:44 PM, Eitan Adler <lists at eitanadler.com> wrote:
> Currently clang crashes if it sees a construct like
>
> double e = 0x.p0;
>
> The following patch seems fix the crash issue and also issues a diagnostic.
>
> Index: lib/Lex/LiteralSupport.cpp
> ===================================================================
> --- lib/Lex/LiteralSupport.cpp  (revision 148238)
> +++ lib/Lex/LiteralSupport.cpp  (working copy)
> @@ -538,6 +538,12 @@
>   // Handle a hex number like 0x1234.
>   if ((*s == 'x' || *s == 'X') && (isxdigit(s[1]) || s[1] == '.')) {
>     s++;
> +    if (!isxdigit(*s)) {
> +      PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), \
> +             diag::err_hexconstant_requires_digits);
> +      hadError = true;
> +      return;
> +    }
>     radix = 16;
>     DigitsBegin = s;
>     s = SkipHexDigits(s);
> Index: test/Lexer/hexfloat.cpp
> ===================================================================
> --- test/Lexer/hexfloat.cpp     (revision 148238)
> +++ test/Lexer/hexfloat.cpp     (working copy)
> @@ -1,4 +1,5 @@
>  // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
>  // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s
>  float f = 0x1p+1; // expected-warning{{hexadecimal floating constants
> are a C99 feature}}
> +double e = 0x.p0; //expected-error{{hexadecimal floating constants
> require a number}}
>
> Index: include/clang/Basic/DiagnosticLexKinds.td
> ===================================================================
> --- include/clang/Basic/DiagnosticLexKinds.td   (revision 148238)
> +++ include/clang/Basic/DiagnosticLexKinds.td   (working copy)
> @@ -111,6 +111,8 @@
>  def ext_imaginary_constant : Extension<"imaginary constants are an extension">;
>  def err_hexconstant_requires_exponent : Error<
>   "hexadecimal floating constants require an exponent">;
> +def err_hexconstant_requires_digits : Error<
> +  "hexadecimal floating constants require a number">;
>  def ext_hexconstant_invalid : Extension<
>   "hexadecimal floating constants are a C99 feature">;
>  def ext_binary_literal : Extension<
>
> --
> Eitan Adler



-- 
Eitan Adler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-bug-7910.patch
Type: application/octet-stream
Size: 1782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120116/f55726c4/attachment.obj>


More information about the cfe-commits mailing list