Commit 68017cb4 by H.J. Lu Committed by H.J. Lu

re PR c++/39188 (G++ doesn't handle static anonymous union right)

gcc/

2009-02-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/39188
	* varasm.c (assemble_variable): Don't check DECL_NAME when
	globalizing a variable.

gcc/cp/

2009-02-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/39188
	* cp-tree.h (maybe_commonize_var): New.

	* decl.c (maybe_commonize_var): Make it extern.

	* decl2.c (finish_anon_union): Call maybe_commonize_var.

gcc/testsuite/

2009-02-19  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/39188
	* g++.dg/abi/pr39188-1a.C: New.
	* g++.dg/abi/pr39188-1b.C: Likewise.
	* g++.dg/abi/pr39188-1.h: Likewise.
	* g++.dg/abi/pr39188-2a.C: Likewise.
	* g++.dg/abi/pr39188-2b.C: Likewise.
	* g++.dg/abi/pr39188-2.h: Likewise.
	* g++.dg/abi/pr39188-3a.C: Likewise.
	* g++.dg/abi/pr39188-3b.C: Likewise.
	* g++.dg/abi/pr39188-3.h: Likewise.

From-SVN: r144297
parent ab4194da
2009-02-19 H.J. Lu <hongjiu.lu@intel.com>
PR c++/39188
* varasm.c (assemble_variable): Don't check DECL_NAME when
globalizing a variable.
2009-02-19 Joseph Myers <joseph@codesourcery.com> 2009-02-19 Joseph Myers <joseph@codesourcery.com>
PR c/38483 PR c/38483
......
2009-02-19 H.J. Lu <hongjiu.lu@intel.com>
PR c++/39188
* cp-tree.h (maybe_commonize_var): New.
* decl.c (maybe_commonize_var): Make it extern.
* decl2.c (finish_anon_union): Call maybe_commonize_var.
2009-02-18 H.J. Lu <hongjiu.lu@intel.com> 2009-02-18 H.J. Lu <hongjiu.lu@intel.com>
PR c++/39219 PR c++/39219
......
...@@ -4360,6 +4360,7 @@ extern tree finish_function (int); ...@@ -4360,6 +4360,7 @@ extern tree finish_function (int);
extern tree start_method (cp_decl_specifier_seq *, const cp_declarator *, tree); extern tree start_method (cp_decl_specifier_seq *, const cp_declarator *, tree);
extern tree finish_method (tree); extern tree finish_method (tree);
extern void maybe_register_incomplete_var (tree); extern void maybe_register_incomplete_var (tree);
extern void maybe_commonize_var (tree);
extern void complete_vars (tree); extern void complete_vars (tree);
extern void finish_stmt (void); extern void finish_stmt (void);
extern void print_other_binding_stack (struct cp_binding_level *); extern void print_other_binding_stack (struct cp_binding_level *);
......
...@@ -81,7 +81,6 @@ static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool); ...@@ -81,7 +81,6 @@ static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
static int walk_namespaces_r (tree, walk_namespaces_fn, void *); static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
static void maybe_deduce_size_from_array_init (tree, tree); static void maybe_deduce_size_from_array_init (tree, tree);
static void layout_var_decl (tree); static void layout_var_decl (tree);
static void maybe_commonize_var (tree);
static tree check_initializer (tree, tree, int, tree *); static tree check_initializer (tree, tree, int, tree *);
static void make_rtl_for_nonlocal_decl (tree, tree, const char *); static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
static void save_function_data (tree); static void save_function_data (tree);
...@@ -4536,7 +4535,7 @@ layout_var_decl (tree decl) ...@@ -4536,7 +4535,7 @@ layout_var_decl (tree decl)
we have a weak definition, we must endeavor to create only one we have a weak definition, we must endeavor to create only one
instance of the variable at link-time. */ instance of the variable at link-time. */
static void void
maybe_commonize_var (tree decl) maybe_commonize_var (tree decl)
{ {
/* Static data in a function with comdat linkage also has comdat /* Static data in a function with comdat linkage also has comdat
......
...@@ -1364,6 +1364,7 @@ finish_anon_union (tree anon_union_decl) ...@@ -1364,6 +1364,7 @@ finish_anon_union (tree anon_union_decl)
{ {
/* Use main_decl to set the mangled name. */ /* Use main_decl to set the mangled name. */
DECL_NAME (anon_union_decl) = DECL_NAME (main_decl); DECL_NAME (anon_union_decl) = DECL_NAME (main_decl);
maybe_commonize_var (anon_union_decl);
mangle_decl (anon_union_decl); mangle_decl (anon_union_decl);
DECL_NAME (anon_union_decl) = NULL_TREE; DECL_NAME (anon_union_decl) = NULL_TREE;
} }
......
2009-02-19 H.J. Lu <hongjiu.lu@intel.com>
PR c++/39188
* g++.dg/abi/pr39188-1a.C: New.
* g++.dg/abi/pr39188-1b.C: Likewise.
* g++.dg/abi/pr39188-1.h: Likewise.
* g++.dg/abi/pr39188-2a.C: Likewise.
* g++.dg/abi/pr39188-2b.C: Likewise.
* g++.dg/abi/pr39188-2.h: Likewise.
* g++.dg/abi/pr39188-3a.C: Likewise.
* g++.dg/abi/pr39188-3b.C: Likewise.
* g++.dg/abi/pr39188-3.h: Likewise.
2009-02-19 Joseph Myers <joseph@codesourcery.com> 2009-02-19 Joseph Myers <joseph@codesourcery.com>
PR c/38483 PR c/38483
......
inline int
f (int x)
{
static union
{
int i;
};
int j = i;
i = x;
return j;
}
// PR c++/39188
// { dg-do run }
// { dg-options "-O2" }
// { dg-additional-sources "pr39188-1b.C" }
#include "pr39188-1.h"
int
x (int i)
{
return f (i);
}
#include "pr39188-1.h"
extern "C" void abort ();
extern int x (int);
int
main (void)
{
if (x (1) != 0)
abort ();
if (f (1) != 1)
abort ();
return 0;
}
template<typename T>
T
f (T x)
{
static union
{
T i;
};
T j = i;
i = x;
return j;
}
// PR c++/39188
// { dg-do run }
// { dg-options "-O2" }
// { dg-additional-sources "pr39188-2b.C" }
#include "pr39188-2.h"
int
x (int i)
{
return f<int> (i);
}
#include "pr39188-2.h"
extern "C" void abort ();
extern int x (int);
int
main (void)
{
if (x (1) != 0)
abort ();
if (f<int> (1) != 1)
abort ();
return 0;
}
static int
f (int x)
{
static union
{
int i;
};
int j = i;
i = x;
return j;
}
// PR c++/39188
// { dg-do run }
// { dg-options "-O2" }
// { dg-additional-sources "pr39188-3b.C" }
#include "pr39188-3.h"
int
x (int i)
{
return f (i);
}
#include "pr39188-3.h"
extern "C" void abort ();
extern int x (int);
int
main (void)
{
if (x (1) != 0)
abort ();
if (f (1) != 0)
abort ();
return 0;
}
...@@ -2161,7 +2161,6 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, ...@@ -2161,7 +2161,6 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
/* First make the assembler name(s) global if appropriate. */ /* First make the assembler name(s) global if appropriate. */
sect = get_variable_section (decl, false); sect = get_variable_section (decl, false);
if (TREE_PUBLIC (decl) if (TREE_PUBLIC (decl)
&& DECL_NAME (decl)
&& (sect->common.flags & SECTION_COMMON) == 0) && (sect->common.flags & SECTION_COMMON) == 0)
globalize_decl (decl); globalize_decl (decl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment