diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr97260.c b/gcc/testsuite/gcc.dg/tree-ssa/pr97260.c new file mode 100644 index 00000000000..9b3723b7834 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr97260.c @@ -0,0 +1,11 @@ +/* PR tree-optimization/97260 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */ + +int +foo (void) +{ + const char a[] = "1234"; + return __builtin_memcmp (a, "1234", 4); +} diff --git a/gcc/varpool.c b/gcc/varpool.c index e0488ed5a12..86f16052984 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "stringpool.h" #include "attribs.h" +#include "tree-pass.h" const char * const tls_model_names[]={"none", "emulated", "global-dynamic", "local-dynamic", @@ -412,6 +413,13 @@ ctor_for_folding (tree decl) if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) { gcc_assert (!TREE_PUBLIC (decl)); + /* Unless this is called during FE folding. */ + if (cfun + && (cfun->curr_properties & (PROP_trees | PROP_rtl)) == 0 + && TREE_READONLY (decl) + && !TREE_SIDE_EFFECTS (decl) + && DECL_INITIAL (decl)) + return DECL_INITIAL (decl); return error_mark_node; }