From af9db3a7b0f36f8027a4781abab31d87dfa44416 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 2 Jun 2015 09:13:29 +0000 Subject: [PATCH] re PR middle-end/66345 (internal compiler error: Segmentation fault) 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 | 6 ++++++ gcc/gimple-fold.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr66345.c | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr66345.c 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]); +}