Skip to content

Commit

Permalink
Be more lenient when accepting complex float consant.
Browse files Browse the repository at this point in the history
iF can also be written Fi
i is the same as Di
References #8, References #9
  • Loading branch information
michael-schwarz committed Jan 16, 2020
1 parent 7e85e55 commit 3fc3b58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
2 changes: 1 addition & 1 deletion src/frontc/clexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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|'_'|'$')*
Expand Down
2 changes: 2 additions & 0 deletions test/small1/c99-complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions test/small1/c99-tgmath.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <tgmath.h>
#include <complex.h>
#include "testharness.h"

int main(void)
Expand All @@ -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);

Expand Down

0 comments on commit 3fc3b58

Please sign in to comment.