From 3fc3b58492125064fee1a853c088bcc3c3caba7c Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Thu, 16 Jan 2020 11:26:55 +0100 Subject: [PATCH] Be more lenient when accepting complex float consant. iF can also be written Fi i is the same as Di References #8, References #9 --- src/frontc/cabs2cil.ml | 10 +++++----- src/frontc/clexer.mll | 2 +- test/small1/c99-complex.c | 2 ++ test/small1/c99-tgmath.c | 7 +++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index 829d9796f..c18982873 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -3583,14 +3583,14 @@ and doExp (asconst: bool) (* This expression is used as a constant *) (* Maybe it ends in U or UL. Strip those *) let l = String.length str in let baseint, kind = - if hasSuffix str "iL" then + if hasSuffix str "iL" || hasSuffix str "Li" then String.sub str 0 (l - 2), FComplexLongDouble - else if hasSuffix str "iF" then + else if hasSuffix str "iF" || hasSuffix str "Fi" then String.sub str 0 (l - 2), FComplexFloat - else if hasSuffix str "iD" then + else if hasSuffix str "iD" || hasSuffix str "Di" then String.sub str 0 (l - 2), FComplexDouble - else - str, FComplexDouble (* this is not ok *) + else (* A.CONST_COMPLEX always has the suffix i *) + String.sub str 0 (l - 1), FComplexDouble in if kind = FLongDouble then (* We only have 64-bit values in Ocaml *) diff --git a/src/frontc/clexer.mll b/src/frontc/clexer.mll index 6985b6da1..8a772e372 100644 --- a/src/frontc/clexer.mll +++ b/src/frontc/clexer.mll @@ -438,7 +438,7 @@ let hexfloat = hexprefix hexfraction binexponent let floatsuffix = ['f' 'F' 'l' 'L'] let floatnum = (decfloat | hexfloat) floatsuffix? -let complexnum = (decfloat | hexfloat) ['i' 'I'] floatsuffix +let complexnum = (decfloat | hexfloat) ((['i' 'I'] floatsuffix) | (floatsuffix? ['i' 'I'])) let ident = (letter|'_'|'$')(letter|decdigit|'_'|'$')* diff --git a/test/small1/c99-complex.c b/test/small1/c99-complex.c index ac8123e25..fdc6a7071 100644 --- a/test/small1/c99-complex.c +++ b/test/small1/c99-complex.c @@ -20,7 +20,9 @@ void forlong() { int main(void) { + double complex x0 = 1.0i + 17; double complex x1 = 1.0iF + 0.5; + double complex x00 = 1.0Fi + 0.5; if(sizeof(double complex) != sizeof(1.0iF + 0.5)) { E(1); diff --git a/test/small1/c99-tgmath.c b/test/small1/c99-tgmath.c index ff2b003d2..5597fbbf8 100644 --- a/test/small1/c99-tgmath.c +++ b/test/small1/c99-tgmath.c @@ -1,5 +1,6 @@ #include #include +#include #include "testharness.h" int main(void) @@ -8,6 +9,12 @@ int main(void) double d = fabs(1.0); long l = fabs(1.0l); + float _Complex fc = 3.25f + 0.1if; + float f2 = fabs(fc); + + double _Complex fcd = 3.25 + 0.1i; + double f2d = fabs(fcd); + if(f != 1.0f) E(1);