[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread rguenth at gcc dot gnu dot org


--- Comment #1 from rguenth at gcc dot gnu dot org  2009-02-14 16:55 ---
Single-file testcase, reproduces with a x86_64-pc-mingw32 cross at any
optimization level.  get_symbol_constant_value returns zero for K::k.

struct K {
static const unsigned k;
};
extern C void abort (void);
int main() {
if ( K::k != 1 )
  abort ();
return 1;
}


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever Confirmed|0   |1
   Last reconfirmed|-00-00 00:00:00 |2009-02-14 16:55:18
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread rguenth at gcc dot gnu dot org


--- Comment #2 from rguenth at gcc dot gnu dot org  2009-02-14 17:03 ---
The problem is that targetm.binds_local_p returns true for

 var_decl 0xb7866000 k
type integer_type 0xb785edd0 unsigned int readonly unsigned SI
size integer_cst 0xb778b4a4 constant 32
unit size integer_cst 0xb778b1f8 constant 4
align 32 symtab 0 alias set -1 canonical type 0xb785edd0 precision 32
min integer_cst 0xb778b4c8 0 max integer_cst 0xb778b480 4294967295
readonly used public static unsigned external nonlocal decl_3 decl_5 decl_6
SI file t.ii line 2 col 27 size integer_cst 0xb778b4a4 32 unit size
integer_cst 0xb778b1f8 4
align 32 context record_type 0xb785ec30 K
chain type_decl 0xb785ed00 K

though probably nobody thought of handling TREE_STATIC  DECL_EXTERNAL being
true at the same time.  Thus, this looks like a possible C++ FE problem to me?

A simple fix would be for i386_pe_binds_local_p to return false if
DECL_EXTERNAL is set, as this is what default_binds_local_p_1 does.
Or better, it should dispatch to default_binds_local_p_1 and only
adjust the shlib flag according to DECL_DLLIMPORT_P.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread ebotcazou at gcc dot gnu dot org


--- Comment #3 from ebotcazou at gcc dot gnu dot org  2009-02-14 17:16 
---
 The problem is that targetm.binds_local_p returns true for
 
  var_decl 0xb7866000 k
 type integer_type 0xb785edd0 unsigned int readonly unsigned SI
 size integer_cst 0xb778b4a4 constant 32
 unit size integer_cst 0xb778b1f8 constant 4
 align 32 symtab 0 alias set -1 canonical type 0xb785edd0 precision 32
 min integer_cst 0xb778b4c8 0 max integer_cst 0xb778b480 4294967295
 readonly used public static unsigned external nonlocal decl_3 decl_5 
 decl_6
 SI file t.ii line 2 col 27 size integer_cst 0xb778b4a4 32 unit size
 integer_cst 0xb778b1f8 4
 align 32 context record_type 0xb785ec30 K
 chain type_decl 0xb785ed00 K
 
 though probably nobody thought of handling TREE_STATIC  DECL_EXTERNAL being
 true at the same time.  Thus, this looks like a possible C++ FE problem to me?

FWIW we had the same problem in Ada on this platform and we fixed Gigi.


-- 

ebotcazou at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||ebotcazou at gcc dot gnu dot
   ||org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread ktietz at gcc dot gnu dot org


--- Comment #6 from ktietz at gcc dot gnu dot org  2009-02-14 20:10 ---
(In reply to comment #2)
 The problem is that targetm.binds_local_p returns true for
 
  var_decl 0xb7866000 k
 type integer_type 0xb785edd0 unsigned int readonly unsigned SI
 size integer_cst 0xb778b4a4 constant 32
 unit size integer_cst 0xb778b1f8 constant 4
 align 32 symtab 0 alias set -1 canonical type 0xb785edd0 precision 32
 min integer_cst 0xb778b4c8 0 max integer_cst 0xb778b480 4294967295
 readonly used public static unsigned external nonlocal decl_3 decl_5 
 decl_6
 SI file t.ii line 2 col 27 size integer_cst 0xb778b4a4 32 unit size
 integer_cst 0xb778b1f8 4
 align 32 context record_type 0xb785ec30 K
 chain type_decl 0xb785ed00 K
 
 though probably nobody thought of handling TREE_STATIC  DECL_EXTERNAL being
 true at the same time.  Thus, this looks like a possible C++ FE problem to me?
 
 A simple fix would be for i386_pe_binds_local_p to return false if
 DECL_EXTERNAL is set, as this is what default_binds_local_p_1 does.
 Or better, it should dispatch to default_binds_local_p_1 and only
 adjust the shlib flag according to DECL_DLLIMPORT_P.
 

Right in winnt.c (i386_pe_bind_local_p) should be something like this patch,
but sadly we get then emitted @GOTPCREL, which aren't handled proper by COFF
targets.

Index: gcc/gcc/config/i386/winnt.c
===
--- gcc.orig/gcc/config/i386/winnt.c
+++ gcc/gcc/config/i386/winnt.c
@@ -321,13 +321,14 @@ i386_pe_encode_section_info (tree decl,
 bool
 i386_pe_binds_local_p (const_tree exp)
 {
+  bool flag = true;
   /* PE does not do dynamic binding.  Indeed, the only kind of
  non-local reference comes from a dllimport'd symbol.  */
   if ((TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == FUNCTION_DECL)
DECL_DLLIMPORT_P (exp))
-return false;
+flag = false;

-  return true;
+  return flag  default_binds_local_p_1 (exp, flag_shlib);
 }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread rguenth at gcc dot gnu dot org


--- Comment #7 from rguenth at gcc dot gnu dot org  2009-02-14 21:12 ---
What happens if you just use

return default_binds_local_p_1 (exp, (TREE_CODE (exp) == VAR_DECL || TREE_CODE
(exp) == FUNCTION_DECL)
DECL_DLLIMPORT_P (exp));

?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread ktietz at gcc dot gnu dot org


--- Comment #8 from ktietz at gcc dot gnu dot org  2009-02-14 21:25 ---
(In reply to comment #7)
 What happens if you just use
 
 return default_binds_local_p_1 (exp, (TREE_CODE (exp) == VAR_DECL || TREE_CODE
 (exp) == FUNCTION_DECL)
 DECL_DLLIMPORT_P (exp));
 
 ?
 

Same issue @GOTPCREL code gets emitted.
...
movq__zn1k...@gotpcrel(%rip), %rax
cmpl$1, (%rax)
...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread nightstrike at gmail dot com


--- Comment #9 from nightstrike at gmail dot com  2009-02-14 22:56 ---
Verified to fail on win32 and win64, not just win64.  Can someone with
sufficient privileges adjust Target?

Verified to work in 4.3, so this is a regression.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179



[Bug target/39179] Wrong code in c++ for const members initialized in external file

2009-02-14 Thread ktietz at gcc dot gnu dot org


-- 

ktietz at gcc dot gnu dot org changed:

   What|Removed |Added

   Priority|P3  |P2
   Target Milestone|--- |4.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39179