From d8028f2cc34c6fe1f5a8b93762195dcdbbd37b71 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 23 Feb 2009 16:23:58 -0500 Subject: [PATCH] re PR c++/38880 (g++.dg/init/const7.C XFAILed) PR c++/38880 * varasm.c (initializer_constant_valid_p) [PLUS_EXPR]: Check narrowing_initializer_constant_valid_p. (narrowing_initializer_constant_valid_p): Don't return null_pointer_node for adding a pointer to itself. From-SVN: r144395 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/init/const7.C | 2 +- gcc/testsuite/g++.dg/init/static-init1.C | 5 +++++ gcc/varasm.c | 18 +++++++++--------- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/static-init1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e63df9dad89..58f0f913854 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2009-02-23 Jason Merrill + + PR c++/38880 + * varasm.c (initializer_constant_valid_p) [PLUS_EXPR]: Check + narrowing_initializer_constant_valid_p. + (narrowing_initializer_constant_valid_p): Don't return + null_pointer_node for adding a pointer to itself. + 2009-02-23 Jan Hubicka PR c/12245 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3ca42825655..9c6b43aec27 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2009-02-23 Jason Merrill + PR c++/38880 + * g++.dg/init/const7.C: Remove XFAIL. + * g++.dg/init/static-init1.C: New test. + * g++.dg/cpp0x/initlist14.C: New test. 2008-02-21 Thomas Koenig diff --git a/gcc/testsuite/g++.dg/init/const7.C b/gcc/testsuite/g++.dg/init/const7.C index 348bd58d690..18d04625db2 100644 --- a/gcc/testsuite/g++.dg/init/const7.C +++ b/gcc/testsuite/g++.dg/init/const7.C @@ -9,5 +9,5 @@ short offsets[1] = { // This ensures that we get a dump whether or not the bug is present. void fn() { } -// { dg-final { scan-tree-dump-not "initialization" "gimple" { xfail *-*-* } } } +// { dg-final { scan-tree-dump-not "initialization" "gimple" } } // { dg-final { cleanup-tree-dump "gimple" } } diff --git a/gcc/testsuite/g++.dg/init/static-init1.C b/gcc/testsuite/g++.dg/init/static-init1.C new file mode 100644 index 00000000000..dddbca1c7a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/static-init1.C @@ -0,0 +1,5 @@ +// Related to the patch for 38880. +// Make sure we don't think we can initialize a at compile time. + +char c; +short a[] = { (short)((int)&c + (int)&c) }; diff --git a/gcc/varasm.c b/gcc/varasm.c index 0589fc93e49..c724fcd721e 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4070,8 +4070,8 @@ constructor_static_from_elts_p (const_tree ctor) && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor))); } -/* A subroutine of initializer_constant_valid_p. VALUE is either a - MINUS_EXPR or a POINTER_PLUS_EXPR. This looks for cases of VALUE +/* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR, + PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE which are valid when ENDTYPE is an integer of any size; in particular, this does not accept a pointer minus a constant. This returns null_pointer_node if the VALUE is an absolute constant @@ -4124,7 +4124,9 @@ narrowing_initializer_constant_valid_p (tree value, tree endtype) /* Both initializers must be known. */ if (op0 && op1) { - if (op0 == op1) + if (op0 == op1 + && (op0 == null_pointer_node + || TREE_CODE (value) == MINUS_EXPR)) return null_pointer_node; /* Support differences between labels. */ @@ -4315,12 +4317,10 @@ initializer_constant_valid_p (tree value, tree endtype) } /* Support narrowing pointer differences. */ - if (TREE_CODE (value) == POINTER_PLUS_EXPR) - { - ret = narrowing_initializer_constant_valid_p (value, endtype); - if (ret != NULL_TREE) - return ret; - } + ret = narrowing_initializer_constant_valid_p (value, endtype); + if (ret != NULL_TREE) + return ret; + break; case MINUS_EXPR: