summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-24 08:51:05 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-24 08:51:05 +0000
commit0f3d70f0f21c1a67189e5fc7cedea638c36f1f62 (patch)
tree4b42632a639078d9ef8f1062fdfbd875b99f3576
parent4ac5a450daf9f4e22dd90f2180cb15c2a4a7dc1f (diff)
downloadppe42-gcc-0f3d70f0f21c1a67189e5fc7cedea638c36f1f62.tar.gz
ppe42-gcc-0f3d70f0f21c1a67189e5fc7cedea638c36f1f62.zip
PR c++/23171
* varasm.c (initializer_constant_valid_p): An ADDR_EXPR of a CONSTRUCTOR is invalid. PR c++/23171 * g++.dg/opt/init1.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109035 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/opt/init1.C4
-rw-r--r--gcc/varasm.c30
4 files changed, 33 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 19c11a7130e..7a3fccff175 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/23171
+ * varasm.c (initializer_constant_valid_p): An ADDR_EXPR of a
+ CONSTRUCTOR is invalid.
+
2005-12-23 Daniel Berlin <dberlin@dberlin.org>
* tree-pass.h (pass_eliminate_useless_stores): Remove.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fd0d3336607..46f37f0c960 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/23171
+ * g++.dg/opt/init1.C: New test.
+
2005-12-23 Mark Mitchell <mark@codesourcery.com>
PR c++/24671
diff --git a/gcc/testsuite/g++.dg/opt/init1.C b/gcc/testsuite/g++.dg/opt/init1.C
new file mode 100644
index 00000000000..d9a139e72a8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/init1.C
@@ -0,0 +1,4 @@
+// PR c++/23171
+// { dg-options "-O" }
+
+int *p = (int*)(int[1]){0};
diff --git a/gcc/varasm.c b/gcc/varasm.c
index f304bb76e3f..f39b07ccc9a 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -3477,18 +3477,24 @@ initializer_constant_valid_p (tree value, tree endtype)
case ADDR_EXPR:
case FDESC_EXPR:
value = staticp (TREE_OPERAND (value, 0));
- /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
- be a constant, this is old-skool offsetof-like nonsense. */
- if (value
- && TREE_CODE (value) == INDIRECT_REF
- && TREE_CONSTANT (TREE_OPERAND (value, 0)))
- return null_pointer_node;
- /* Taking the address of a nested function involves a trampoline. */
- if (value
- && TREE_CODE (value) == FUNCTION_DECL
- && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
- || DECL_DLLIMPORT_P (value)))
- return NULL_TREE;
+ if (value)
+ {
+ /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
+ be a constant, this is old-skool offsetof-like nonsense. */
+ if (TREE_CODE (value) == INDIRECT_REF
+ && TREE_CONSTANT (TREE_OPERAND (value, 0)))
+ return null_pointer_node;
+ /* Taking the address of a nested function involves a trampoline. */
+ if (TREE_CODE (value) == FUNCTION_DECL
+ && ((decl_function_context (value)
+ && !DECL_NO_STATIC_CHAIN (value))
+ || DECL_DLLIMPORT_P (value)))
+ return NULL_TREE;
+ /* "&{...}" requires a temporary to hold the constructed
+ object. */
+ if (TREE_CODE (value) == CONSTRUCTOR)
+ return NULL_TREE;
+ }
return value;
case VIEW_CONVERT_EXPR:
OpenPOWER on IntegriCloud