re PR middle-end/66345 (internal compiler error: Segmentation fault)
authorMarek Polacek <polacek@redhat.com>
Tue, 2 Jun 2015 09:13:29 +0000 (09:13 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 2 Jun 2015 09:13:29 +0000 (09:13 +0000)
PR middle-end/66345
* gimple-fold.c (gimple_fold_builtin_snprintf): Return false if
get_maxval_strlen does not produce an INTEGER_CST.

* gcc.dg/torture/pr66345.c: New test.

From-SVN: r224016

gcc/ChangeLog
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr66345.c [new file with mode: 0644]

index 3a01820579a6b18696eededa9e99a26d8669e4b3..2dc9702a54e3857361507d3e0023c7153506bf9b 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-02  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/66345
+       * gimple-fold.c (gimple_fold_builtin_snprintf): Return false if
+       get_maxval_strlen does not produce an INTEGER_CST.
+
 2015-06-02  Richard Sandiford  <richard.sandiford@arm.com>
 
        * config/arc/constraints.md: Use lower-case names in match_code.
index c91f218c218ca4a90d1b9ef403f0a7ae1b2908ee..b2ce851d4894e1e21b72168afa77274022f6fd26 100644 (file)
@@ -2530,7 +2530,7 @@ gimple_fold_builtin_snprintf (gimple_stmt_iterator *gsi)
        return false;
 
       tree orig_len = get_maxval_strlen (orig, 0);
-      if (!orig_len)
+      if (!orig_len || TREE_CODE (orig_len) != INTEGER_CST)
        return false;
 
       /* We could expand this as
index 9dd08e5b581e16c9472f92a6469f727b27d5da46..b87940810651e5a0bc1abb26e2d88ba17b3b4e52 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-02  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/66345
+       * gcc.dg/torture/pr66345.c: New test.
+
 2015-06-02  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/65961
diff --git a/gcc/testsuite/gcc.dg/torture/pr66345.c b/gcc/testsuite/gcc.dg/torture/pr66345.c
new file mode 100644 (file)
index 0000000..1687987
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+extern int snprintf (char *, unsigned long, const char *, ...);
+const char a[] = "";
+int b;
+void
+get_bar ()
+{
+  snprintf (0, 0, "%s", &a[b]);
+}