PR tree-optimization/86274 - SEGFAULT when logging std::to_string(NAN)
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-sprintf.c
blob6f8b7a9fb1b70a34404fbce1c910cc4957e860c9
1 /* PR tree-optimization/86274 - SEGFAULT when logging std::to_string(NAN)
2 { dg-do run }
3 { dg-options "-O2 -Wall" } */
5 #define X "0xdeadbeef"
6 #define nan(x) __builtin_nan (x)
8 volatile double nan_0 = nan ("0");
9 volatile double nan_x = nan (X);
11 int main (void)
13 char buf[80];
15 /* Verify that folded results match those of the library calls. */
16 int cst_n_0 = __builtin_sprintf (buf, "%g", nan ("0"));
17 int cst_n_x = __builtin_sprintf (buf, "%g", nan (X));
19 int var_n_0 = __builtin_sprintf (buf, "%g", nan_0);
20 int var_n_x = __builtin_sprintf (buf, "%g", nan_x);
22 if (cst_n_0 != var_n_0)
23 __builtin_abort ();
25 if (cst_n_x != var_n_x)
26 __builtin_abort ();
28 return 0;