diff gcc/testsuite/gcc.dg/torture/builtin-sprintf.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children 1830386684a0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/torture/builtin-sprintf.c	Thu Oct 25 07:37:49 2018 +0900
@@ -0,0 +1,29 @@
+/* PR tree-optimization/86274 - SEGFAULT when logging std::to_string(NAN)
+   { dg-do run }
+   { dg-options "-O2 -Wall" } */
+
+#define X        "0xdeadbeef"
+#define nan(x)   __builtin_nan (x)
+
+volatile double nan_0 = nan ("0");
+volatile double nan_x = nan (X);
+
+int main (void)
+{
+  char buf[80];
+
+  /* Verify that folded results match those of the library calls.  */
+  int cst_n_0 = __builtin_sprintf (buf, "%g", nan ("0"));
+  int cst_n_x = __builtin_sprintf (buf, "%g", nan (X));
+
+  int var_n_0 = __builtin_sprintf (buf, "%g", nan_0);
+  int var_n_x = __builtin_sprintf (buf, "%g", nan_x);
+
+  if (cst_n_0 != var_n_0)
+    __builtin_abort ();
+
+  if (cst_n_x != var_n_x)
+    __builtin_abort ();
+
+  return 0;
+}