diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3a01820579a..2dc9702a54e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-06-02 Marek Polacek + + 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 * config/arc/constraints.md: Use lower-case names in match_code. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index c91f218c218..b2ce851d489 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9dd08e5b581..b8794081065 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-02 Marek Polacek + + PR middle-end/66345 + * gcc.dg/torture/pr66345.c: New test. + 2015-06-02 Richard Biener 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 index 00000000000..16879872694 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr66345.c @@ -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]); +}