Accept more floating point constant expressions

the rules for constant expressions in static initializers are more
relaxed than for integer constant expressions.  We need to accept
0.0/0.0 in static initializers (in non-static initializers the potential
exceptions need to be raised though, so no translation-time calculation
then).
This commit is contained in:
Michael Matz 2017-12-25 12:44:29 +01:00
parent 9e47b18229
commit 414b224efa
2 changed files with 8 additions and 3 deletions

View File

@ -2049,9 +2049,10 @@ static void gen_opif(int op)
case '*': f1 *= f2; break;
case '/':
if (f2 == 0.0) {
if (const_wanted)
tcc_error("division by zero in constant");
goto general_case;
/* If not in initializer we need to potentially generate
FP exceptions at runtime, otherwise we want to fold. */
if (!const_wanted)
goto general_case;
}
f1 /= f2;
break;

View File

@ -2234,6 +2234,9 @@ void float_test(void)
double da, db;
int a;
unsigned int b;
static double nan2 = 0.0/0.0;
static double inf1 = 1.0/0.0;
static double inf2 = 1e5000;
printf("float_test:\n");
printf("sizeof(float) = %d\n", sizeof(float));
@ -2255,6 +2258,7 @@ void float_test(void)
b = 4000000000;
db = b;
printf("db = %f\n", db);
printf("nan != nan = %d, inf1 = %f, inf2 = %f\n", nan2 != nan2, inf1, inf2);
#endif
}