Bug 39188 - G++ doesn't handle static anonymous union right
Summary: G++ doesn't handle static anonymous union right
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-02-14 00:35 UTC by H.J. Lu
Modified: 2009-02-19 18:25 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-02-14 00:35:23 UTC
 
Comment 1 H.J. Lu 2009-02-14 00:38:23 UTC
[hjl@gnu-6 936]$ cat x.cc
#include "foo.h"

int *
x (void)
{
  return f ();
}
[hjl@gnu-6 936]$ cat y.cc
#include <stdio.h>
#include "foo.h"

extern int *x (void);

int
main ()
{
  printf ("%p, %p\n", x (), f ());
  return 0;
}
[hjl@gnu-6 936]$ cat foo.h
inline int *
f ()
{
  static union 
    {
      const char *p;
      int i;
    };
  return &i;
}
[hjl@gnu-6 936]$  g++ x.cc y.cc -O2
[hjl@gnu-6 936]$ ./a.out 
0x600a38, 0x600a40
[hjl@gnu-6 936]$ nm x.o | c++filt 
0000000000000000 W f()
0000000000000000 T x()
0000000000000000 b f()::p
                 U __gxx_personality_v0

f()::p should be global and linkonce.
Comment 2 H.J. Lu 2009-02-15 19:47:18 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00714.html
Comment 3 H.J. Lu 2009-02-18 23:45:49 UTC
(In reply to comment #2)
> A patch is posted at
> 
> http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00714.html
> 

Jason, Richard, can you review this wrong-code fix? Thanks.
Comment 4 hjl@gcc.gnu.org 2009-02-19 15:22:42 UTC
Subject: Bug 39188

Author: hjl
Date: Thu Feb 19 15:22:28 2009
New Revision: 144297

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144297
Log:
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.

Added:
    trunk/gcc/testsuite/g++.dg/abi/pr39188-1.h
    trunk/gcc/testsuite/g++.dg/abi/pr39188-1a.C
    trunk/gcc/testsuite/g++.dg/abi/pr39188-1b.C
    trunk/gcc/testsuite/g++.dg/abi/pr39188-2.h
    trunk/gcc/testsuite/g++.dg/abi/pr39188-2a.C
    trunk/gcc/testsuite/g++.dg/abi/pr39188-2b.C
    trunk/gcc/testsuite/g++.dg/abi/pr39188-3.h
    trunk/gcc/testsuite/g++.dg/abi/pr39188-3a.C
    trunk/gcc/testsuite/g++.dg/abi/pr39188-3b.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varasm.c

Comment 5 H.J. Lu 2009-02-19 18:25:29 UTC
Fixed.