This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

(1.1b/x86-win32) C++ bug in taking address of dllimported variable


EGCS 1.1 C++ x86-*win32 front-end chokes on the following code (defining
AVOID_BUG works around it, but that's awkward for lot of existing code):
  
    struct 
    #ifdef AVOID_BUG
    __attribute__((dllimport)) 
    #endif
    B { };

    __attribute__((dllimport)) B p;

    void
    foo ()
    {
      B* localp = &p;		// <<<<<< DIES HERE.
    }

The call-tree leading up to the crash is the following:
  yyparse
    build_x_unary_op
      build_new_op
        lookup_function_nonclass
          lookup_arg_dependent
	    arg_assoc_args
	      arg_assoc		<<< BEGINNING OF TROUBLE (TREE_TYPE)
		arg_assoc_type
		  arg_assoc_class
		    decl_namespace <<<< CRASH

The trouble is that TREE_TYPE in ``arg_assoc' is not returning what's 
expected, and eventually we get a crash.

NOTE: This does not happen with development snapshots, and I'd like
to of course figure what changed to fix this and hopefully get that
in the release branch.

I've attached the following:
  c++dllimp.ii 		-- preprocessed
  gdb.run 		-- gdb trace using egcs-1.1 with lots of detail
  gdb.run-new		-- gdb trace using recent development snapshot
			   that shows the different return value of
			   TREE_TYPE (n).

Regards,
Mumit

# 1 "c++dllimp.cc"
struct 



B { };

__attribute__(( dllimport ))  B p;

void
foo ()
{
  B* localp = &p;
}
% gdb ../gcc/cc1plus
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x8077fa3 in decl_namespace (decl=0x0) at ../../../gcc/cp/decl2.c:4133
4133      while (DECL_CONTEXT (decl))
(gdb) where
#0  0x8077fa3 in decl_namespace (decl=0x0) at ../../../gcc/cp/decl2.c:4133
#1  0x8078337 in arg_assoc_class (k=0xbffff2f0, type=0x822492c)
    at ../../../gcc/cp/decl2.c:4276
#2  0x807879d in arg_assoc_type (k=0xbffff2f0, type=0x822492c)
    at ../../../gcc/cp/decl2.c:4329
#3  0x8078942 in arg_assoc (k=0xbffff2f0, n=0x82248a4)
    at ../../../gcc/cp/decl2.c:4390
#4  0x80788b8 in arg_assoc_args (k=0xbffff2f0, args=0x82070c4)
    at ../../../gcc/cp/decl2.c:4371
#5  0x8078a06 in lookup_arg_dependent (name=0x82046f4, fns=0x0, args=0x82070c4)
    at ../../../gcc/cp/decl2.c:4422
#6  0x8054213 in lookup_function_nonclass (name=0x82046f4, args=0x82070c4)
    at ../../../gcc/cp/decl.c:5128
#7  0x804ca0c in build_new_op (code=ADDR_EXPR, flags=3, arg1=0x82248a4, 
    arg2=0x0, arg3=0x0) at ../../../gcc/cp/call.c:2630
#8  0x8093371 in build_x_unary_op (code=ADDR_EXPR, xarg=0x82248a4)
    at ../../../gcc/cp/typeck.c:4192
#9  0x8087e5e in yyparse () at parse.y:1046
#10 0x80aeb6a in compile_file (name=0xbffffd5b "c++dllimp.ii")
    at ../../gcc/toplev.c:2768
#11 0x80b15a6 in main (argc=3, argv=0xbffffc5c, envp=0xbffffc6c)
    at ../../gcc/toplev.c:4838
(gdb) quit

% gdb ../gcc/cc1plus 
(gdb) list arg_assoc
4376	
4377	static int
4378	arg_assoc (k, n)
4379	     struct arg_lookup* k;
4380	     tree n;
4381	{
4382	  if (n == error_mark_node)
4383	    return 0;
4384	
4385	  if (TREE_CODE_CLASS (TREE_CODE (n)) == 't')
4386	    return arg_assoc_type (k, n);
4387	
(gdb) b 4389
Breakpoint 4 at 0x8076715: file ../../../gcc/cp/decl2.c, line 4389.
(gdb) run -quiet c++dllimp.ii
Starting program: ../gcc/cc1plus -quiet c++dllimp.ii
Breakpoint 4, arg_assoc (k=0xbffff270, n=0x82223b4)
    at ../../../gcc/cp/decl2.c:4389
4389	    return arg_assoc_type (k, TREE_TYPE (n));
(gdb) p n
$1 = 0x82223b4
(gdb) pt
 <var_decl 0x82223b4 p
    type <record_type 0x822243c B allocated from permanent_obstack
        permanent type_1 type_5 QI
        size <integer_cst 0x820c768 constant permanent 8>
        align 8 symtab 0 alias set -1
        attributes <tree_list 0x8222428 allocated from permanent_obstack
            permanent
            purpose <identifier_node 0x8222318 dllimport allocated from permanent_obstack
                permanent
                bindings <binding 0x822234c allocated from permanent_obstack
                    permanent scope <namespace_decl 0x820b37c ::>>>>
        fields <type_decl 0x821e0ac B type <record_type 0x821de74 B>
            allocated from permanent_obstack
            permanent nonlocal VOID file c++dllimp.cc line 5
            align 1 context <record_type 0x821de74 B>
            decl-main-variant 0x821e0ac>
        X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
        member-functions <tree_vec 0x82156b0 not allocated from any obstack
           
            elt 0 <overload 0x8222260>
            elt 2 <function_decl 0x82220e8 __as>>>
    allocated from permanent_obstack
    used permanent public static external QI file c++dllimp.cc line 7 size <integer_cst 0x820c768 8>
    align 8 machine_attributes <tree_list 0x8222414>
    (mem/s:QI (mem:SI (symbol_ref:SI ("@i._imp__p")))) chain <type_decl 0x821e00c B>>
(gdb) s
arg_assoc_type (k=0xbffff270, type=0x822243c) at ../../../gcc/cp/decl2.c:4316
4316	  switch (TREE_CODE (type))
(gdb) p type
$2 = 0x822243c
(gdb) pt
 <record_type 0x822243c B allocated from permanent_obstack
    permanent type_1 type_5 QI
    size <integer_cst 0x820c768 type <integer_type 0x820b5dc int> constant permanent 8>
    align 8 symtab 0 alias set -1
    attributes <tree_list 0x8222428 allocated from permanent_obstack
        permanent
        purpose <identifier_node 0x8222318 dllimport allocated from permanent_obstack
            permanent
            bindings <binding 0x822234c allocated from permanent_obstack
                permanent scope <namespace_decl 0x820b37c ::>>>>
    fields <type_decl 0x821e0ac B
        type <record_type 0x821de74 B allocated from permanent_obstack
            permanent type_1 type_5 QI size <integer_cst 0x820c768 8>
            align 8 symtab 0 alias set -1 fields <type_decl 0x821e0ac B>
            X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
            member-functions <tree_vec 0x82156b0 not allocated from any obstack
               
                elt 0 <overload 0x8222260>
                elt 2 <function_decl 0x82220e8 __as>>
            pointer_to_this <pointer_type 0x821df98> reference_to_this <reference_type 0x8221f3c> chain <type_decl 0x821e00c B>>
        allocated from permanent_obstack
        permanent nonlocal VOID file c++dllimp.cc line 5
        align 1 context <record_type 0x821de74 B>
        decl-main-variant 0x821e0ac>
    X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown member-functions <tree_vec 0x82156b0>>
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
decl_namespace (decl=0x0) at ../../../gcc/cp/decl2.c:4132
4132	  while (DECL_CONTEXT (decl))
(gdb) print decl
$3 = 0x0
(gdb) up
#1  0x80762ad in arg_assoc_class (k=0xbffff270, type=0x822243c)
    at ../../../gcc/cp/decl2.c:4275
4275	  context = decl_namespace (TYPE_MAIN_DECL (type));
(gdb) p type
$4 = 0x822243c
(gdb) pt
 <record_type 0x822243c B allocated from permanent_obstack
    permanent type_1 type_5 QI
    size <integer_cst 0x820c768 type <integer_type 0x820b5dc int> constant permanent 8>
    align 8 symtab 0 alias set -1
    attributes <tree_list 0x8222428 allocated from permanent_obstack
        permanent
        purpose <identifier_node 0x8222318 dllimport allocated from permanent_obstack
            permanent
            bindings <binding 0x822234c allocated from permanent_obstack
                permanent scope <namespace_decl 0x820b37c ::>>>>
    fields <type_decl 0x821e0ac B
        type <record_type 0x821de74 B allocated from permanent_obstack
            permanent type_1 type_5 QI size <integer_cst 0x820c768 8>
            align 8 symtab 0 alias set -1 fields <type_decl 0x821e0ac B>
            X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
            member-functions <tree_vec 0x82156b0 not allocated from any obstack
               
                elt 0 <overload 0x8222260>
                elt 2 <function_decl 0x82220e8 __as>>
            pointer_to_this <pointer_type 0x821df98> reference_to_this <reference_type 0x8221f3c> chain <type_decl 0x821e00c B>>
        allocated from permanent_obstack
        permanent nonlocal VOID file c++dllimp.cc line 5
        align 1 context <record_type 0x821de74 B>
        decl-main-variant 0x821e0ac>
    X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown member-functions <tree_vec 0x82156b0>>
(gdb) quit

$ gdb ../gcc/cc1plus
(gdb) list arg_assoc
4585	
4586	static int
4587	arg_assoc (k, n)
4588	     struct arg_lookup* k;
4589	     tree n;
4590	{
4591	  if (n == error_mark_node)
4592	    return 0;
4593	
4594	  if (TREE_CODE_CLASS (TREE_CODE (n)) == 't')
4595	    return arg_assoc_type (k, n);
4596	
4597	  if (! type_unknown_p (n))
4598	    return arg_assoc_type (k, TREE_TYPE (n));
4599	
(gdb) b 4598
Breakpoint 4 at 0x808be32: file ../../../gcc/cp/decl2.c, line 4598.
(gdb) run -quiet c++dllimp.ii
Starting program: ../gcc/cc1plus -quiet c++dllimp.ii
Breakpoint 4, arg_assoc (k=0xbffff274, n=0x82f60e4)
    at ../../../gcc/cp/decl2.c:4598
4598	    return arg_assoc_type (k, TREE_TYPE (n));
(gdb) p n
$1 = 0x82f60e4
(gdb) pt
 <var_decl 0x82f60e4 p
    type <record_type 0x82f4bc0 B allocated from permanent_obstack
        permanent type_1 type_5 QI
        size <integer_cst 0x82e27f0 constant permanent 8>
        align 8 symtab 0 alias set -1
        fields <type_decl 0x82f4df4 B type <record_type 0x82f4bc0 B>
            allocated from permanent_obstack
            permanent nonlocal VOID file c++dllimp.cc line 5
            align 1 context <record_type 0x82f4bc0 B>
            decl-main-variant 0x82f4df4>
        X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
        member-functions <tree_vec 0x82eb6a8 not allocated from any obstack
           
            elt 0 <overload 0x82f5f90>
            elt 2 <function_decl 0x82f5e18 __as>>
        pointer_to_this <pointer_type 0x82f4ce0> reference_to_this <reference_type 0x82f5c6c> chain <type_decl 0x82f4d54 B>>
    allocated from permanent_obstack
    used permanent public static external QI file c++dllimp.cc line 7 size <integer_cst 0x82e27f0 8>
    align 8 machine_attributes <tree_list 0x82f6144>
    (mem/s:QI (mem:SI (symbol_ref:SI ("@i._imp__p")) 0) 0) chain <type_decl 0x82f4d54 B>>
(gdb) s
arg_assoc_type (k=0xbffff274, type=0x82f4bc0) at ../../../gcc/cp/decl2.c:4525
4525	  switch (TREE_CODE (type))
(gdb) p type
$2 = 0x82f4bc0
(gdb) pt
 <record_type 0x82f4bc0 B allocated from permanent_obstack
    permanent type_1 type_5 QI
    size <integer_cst 0x82e27f0 type <integer_type 0x82e26b8 int> constant permanent 8>
    align 8 symtab 0 alias set -1
    fields <type_decl 0x82f4df4 B type <record_type 0x82f4bc0 B>
        allocated from permanent_obstack
        permanent nonlocal VOID file c++dllimp.cc line 5
        align 1 context <record_type 0x82f4bc0 B>
        decl-main-variant 0x82f4df4>
    X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
    member-functions <tree_vec 0x82eb6a8 not allocated from any obstack
       
        elt 0 <overload 0x82f5f90>
        elt 2 <function_decl 0x82f5e18 __as>>
    pointer_to_this <pointer_type 0x82f4ce0> reference_to_this <reference_type 0x82f5c6c> chain <type_decl 0x82f4d54 B>>
(gdb) nb decl_namespace
Breakpoint 5 at 0x808b6a3: file ../../../gcc/cp/decl2.c, line 4341.
(gdb) c
Continuing.

Breakpoint 5, decl_namespace (decl=0x82f4d54) at ../../../gcc/cp/decl2.c:4341
4341	  while (DECL_CONTEXT (decl))
(gdb) p decl
$3 = 0x82f4d54
(gdb) pt
 <type_decl 0x82f4d54 B
    type <record_type 0x82f4bc0 B allocated from permanent_obstack
        permanent type_1 type_5 QI
        size <integer_cst 0x82e27f0 constant permanent 8>
        align 8 symtab 0 alias set -1
        fields <type_decl 0x82f4df4 B type <record_type 0x82f4bc0 B>
            allocated from permanent_obstack
            permanent nonlocal VOID file c++dllimp.cc line 5
            align 1 context <record_type 0x82f4bc0 B>
            decl-main-variant 0x82f4df4>
        X() X(constX&) has= this=(X&) n_parents 0 n_ancestors 0 use_template=0 interface-unknown
        member-functions <tree_vec 0x82eb6a8 not allocated from any obstack
           
            elt 0 <overload 0x82f5f90>
            elt 2 <function_decl 0x82f5e18 __as>>
        pointer_to_this <pointer_type 0x82f4ce0> reference_to_this <reference_type 0x82f5c6c> chain <type_decl 0x82f4d54 B>>
    allocated from permanent_obstack
    permanent QI file c++dllimp.cc line 5 size <integer_cst 0x82e27f0 8>
    align 8 chain <var_decl 0x82eda84 __PRETTY_FUNCTION__>>
(gdb) up
#1  0x808ba4b in arg_assoc_class (k=0xbffff274, type=0x82f4bc0)
    at ../../../gcc/cp/decl2.c:4484
4484	  context = decl_namespace (TYPE_MAIN_DECL (type));
(gdb) quit

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]