This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa][c++] fix pr13898
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Wed, 28 Jan 2004 12:35:56 -0800
- Subject: [tree-ssa][c++] fix pr13898
This is a workaround for something that doesn't seem quite right
in the C++ front end. It would be nice if the C++ fe didn't try
to do the mangling thing with variables that don't need it.
Perhaps we'd be better off with a langhook to "static-ize"?
r~
PR middle-end/13898
* gimplify.c (gimplify_init_constructor): Invoke
lhd_set_decl_assembler_name on the now-static variable.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.138
diff -c -p -d -r1.1.2.138 gimplify.c
*** gimplify.c 28 Jan 2004 09:17:50 -0000 1.1.2.138
--- gimplify.c 28 Jan 2004 20:24:09 -0000
*************** gimplify_init_constructor (tree *expr_p,
*** 1172,1177 ****
--- 1172,1187 ----
TREE_STATIC (object) = 1;
if (!DECL_NAME (object))
DECL_NAME (object) = create_tmp_var_name ("C");
+
+ /* ??? C++ doesn't automatically append a .<number> to the
+ assembler name, and even when it does, it looks a FE private
+ data structures to figure out what that number should be,
+ which are not set for this variable. I suppose this is
+ important for local statics for inline functions, which aren't
+ "local" in the object file sense. So in order to get a unique
+ TU-local symbol, we must invoke the lhd version now. */
+ lhd_set_decl_assembler_name (object);
+
*expr_p = build_empty_stmt ();
break;
}
Index: testsuite/g++.dg/opt/static4.C
===================================================================
RCS file: testsuite/g++.dg/opt/static4.C
diff -N testsuite/g++.dg/opt/static4.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/static4.C 28 Jan 2004 20:24:10 -0000
***************
*** 0 ****
--- 1,15 ----
+ // PR 13898
+ // Make sure the two X variables get assigned unique assembler names
+ // if they are promoted to static storage.
+
+ // { dg-do compile }
+
+ int g(int i) {
+ if (i<1) {
+ const int x[3] = { 1,2,3 };
+ return x[i];
+ } else {
+ const int x[3] = { 4,5,6 };
+ return x[i];
+ }
+ }