Bug 11503 - [3.3/3.4 Regression] segfault when instantiating template with ADDR_EXPR
Summary: [3.3/3.4 Regression] segfault when instantiating template with ADDR_EXPR
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.1
: P1 critical
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2003-07-11 19:13 UTC by Josef Zlomek
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host: i686-linux-gnu
Target: i686-linux-gnu
Build: i686-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-11 19:14:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Josef Zlomek 2003-07-11 19:13:12 UTC
class x
{
public:
    void foo ()
    {}
};

template <class T>
class vector
{
public:
    T& operator[](unsigned int n)
    {}
};

template <class T>
class y
{
public:
    typedef struct
    {   
        T t;
    } s;
    vector<s> array;
    void foo ()
    {
            array[0].t.foo();
    }
};

typedef y<x> z;

inline void test (z &zz)
{   
    zz.foo ();
}


#0  0x080d9943 in lookup_base (t=0x401c8b60, base=0x401c8b60, access=ba_check,
kind_ptr=0x0) at ../../gcc/cp/search.c:376
#1  0x080c7393 in build_unary_op (code=ADDR_EXPR, xarg=0x401d14c0, noconvert=0)
at ../../gcc/cp/typeck.c:4332
#2  0x0804e156 in build_this (obj=0x401d14c0) at ../../gcc/cp/call.c:2475
#3  0x08053917 in build_new_method_call (instance=0x401d14c0, fns=0x401d14e0,
args=0x0, conversion_path=0x0, flags=3) at ../../gcc/cp/call.c:4939
#4  0x0804a7d4 in build_method_call (instance=0x401d14c0, name=0x401c1800,
parms=0x0, basetype_path=0x0, flags=3) at ../../gcc/cp/call.c:587
#5  0x080a011d in build_expr_from_tree (t=0x401d1180) at ../../gcc/cp/decl2.c:3357
#6  0x080839bd in tsubst_expr (t=0x40189e00, args=0x401c7c58, complain=3,
in_decl=0x401c82a0) at ../../gcc/cp/pt.c:7581
#7  0x08083ada in tsubst_expr (t=0x401c71f4, args=0x401c7c58, complain=3,
in_decl=0x401c82a0) at ../../gcc/cp/pt.c:7606
#8  0x08084068 in tsubst_expr (t=0x401c71e0, args=0x401c7c58, complain=3,
in_decl=0x401c82a0) at ../../gcc/cp/pt.c:7753
#9  0x08084068 in tsubst_expr (t=0x401c71cc, args=0x401c7c58, complain=3,
in_decl=0x401c82a0) at ../../gcc/cp/pt.c:7753
#10 0x080885c8 in instantiate_decl (d=0x401ce230, defer_ok=0) at
../../gcc/cp/pt.c:10466
#11 0x080a32ce in mark_used (decl=0x401ce230) at ../../gcc/cp/decl2.c:4884
#12 0x08052e82 in build_over_call (cand=0x401c6604, args=0x401c7fb4, flags=3) at
../../gcc/cp/call.c:4658
#13 0x08053ed6 in build_new_method_call (instance=0x401c73fc, fns=0x401ce230,
args=0x0, conversion_path=0x401c9000, flags=3) at ../../gcc/cp/call.c:5087
#14 0x0804a7d4 in build_method_call (instance=0x401c73fc, name=0x401c1800,
parms=0x0, basetype_path=0x0, flags=3) at ../../gcc/cp/call.c:587
#15 0x080e0faa in finish_object_call_expr (fn=0x401c1800, object=0x401c73fc,
args=0x0) at ../../gcc/cp/semantics.c:1386
#16 0x080b1774 in yyparse () at parse.y:1725
#17 0x0810b2d3 in c_common_parse_file (set_yydebug=0) at ../../gcc/c-lex.c:159
#18 0x083b3217 in compile_file () at ../../gcc/toplev.c:2198
#19 0x083b98ab in do_compile () at ../../gcc/toplev.c:5614
#20 0x083b9918 in toplev_main (argc=2, argv=0xbffff6c4) at ../../gcc/toplev.c:5644
#21 0x08113136 in main (argc=2, argv=0xbffff6c4) at ../../gcc/main.c:35
#22 0x400439ed in __libc_start_main () from /lib/libc.so.6
Comment 1 Josef Zlomek 2003-07-11 19:14:31 UTC
The bug is also present on mainline.
Comment 2 Andrew Pinski 2003-07-11 19:19:06 UTC
Please do not confirm your own bug so that if you got something wrong there can be some peer 
review.

But this is a regression from 3.2.3, where it did not ICE.
On the mainline (20030711) and 3.3.1 (20030707), I do get the ICE.
Here part of the 3.4 backtrace:
#0  0x0812f402 in lookup_base (t=0x400b472c, base=0x400b472c, access=ba_check, 
kind_ptr=0x0) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/search.c:311
#1  0x08114826 in build_unary_op (code=ADDR_EXPR, xarg=0x400bbaa0, 
noconvert=1074431140) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/typeck.c:4246
#2  0x0804f811 in build_this (obj=0x64) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/
call.c:2290
#3  0x08057275 in build_new_method_call (instance=0x400557f8, fns=0x40055810, args=0x0, 
conversion_path=0x0, flags=3) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/call.c:4919
#4  0x080ad4aa in tsubst_copy_and_build (t=0x40055408, args=0x400b6794, complain=3, 
in_decl=0x400b0ec4) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/pt.c:8201
#5  0x080a8c86 in tsubst_expr (t=0x400add0c, args=0x400b6794, complain=3, 
in_decl=0x400b0ec4) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/pt.c:7595
#6  0x080a8bff in tsubst_expr (t=0x400adce4, args=0x400b6794, complain=3, 
in_decl=0x400b0ec4) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/pt.c:7744
#7  0x080a8bff in tsubst_expr (t=0x400adcd0, args=0x400b6794, complain=3, 
in_decl=0x400b0ec4) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/pt.c:7744
#8  0x080b697f in instantiate_decl (d=0x400b8d14, defer_ok=0) at /home/gates/pinskia/src/
gnu/gcc/src/gcc/cp/pt.c:11005
#9  0x080e4e75 in mark_used (decl=0x400b8d14) at /home/gates/pinskia/src/gnu/gcc/src/gcc/
cp/decl2.c:4248
#10 0x080556db in build_over_call (cand=0x400b265c, flags=3) at /home/gates/pinskia/src/
gnu/gcc/src/gcc/cp/call.c:4587
#11 0x080578a9 in build_new_method_call (instance=0x400adf28, fns=0x400b8d14, args=0x0, 
conversion_path=0x400aad80, flags=3) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/
call.c:5077
#12 0x080f6c8f in cp_parser_postfix_expression (parser=0x400aa540, address_p=false) at /
home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:3857
#13 0x080f7590 in cp_parser_unary_expression (parser=0x400aa540, address_p=false) at /
home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:4363
#14 0x08101b79 in cp_parser_simple_cast_expression (parser=0x64) at /home/gates/pinskia/
src/gnu/gcc/src/gcc/cp/parser.c:13918
#15 0x08101212 in cp_parser_binary_expression (parser=0x400aa540, 
token_tree_map=0x849d2dc, fn=0x8101b60 <cp_parser_simple_cast_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13436
#16 0x080f7f01 in cp_parser_pm_expression (parser=0x64) at /home/gates/pinskia/src/gnu/
gcc/src/gcc/cp/parser.c:4818
...
Comment 3 Andrew Pinski 2003-07-11 19:23:08 UTC
From Phil's regression hunter:  Search converges between 2003-06-25-trunk (#225) and 2003-
06-26-trunk (#226).
Comment 4 Andrew Pinski 2003-07-11 19:24:18 UTC
From Phil's regression hunter: Search converges between 2003-06-25-3.3 (#149) and 2003-06-
26-3.3 (#150)
Comment 5 Wolfgang Bangerth 2003-07-11 20:44:03 UTC
I can't compress the testcase much more:
------------------------------
struct x {
    int foo () {}
};

template <class T>
struct vector {
    T& bar () {}
};

template <class T>
struct y {
    typedef struct {   
        x t;
    } s;
    
    vector<s> array;

    int foo ()
      { return array.bar().t.foo(); }
};
int i = y<x>().foo ();
------------------------------------
The most interesting observation is probably that if I replace the
  typedef struct {...} s;
stuff with simply
  struct s {...};
then the ICE goes away. So maybe it has to do with a bad interaction of
templates and anonymous struct.s

W.
Comment 6 s.bosscher 2003-07-12 14:12:24 UTC
Subject:  [3.3/3.4 regression] segfault when instantiating
	template with ADDR_EXPR

The only patches that went onto both the branch and the trunk
between 2003-06-25 and 2003-06-26 are:

2003-06-26  Mark Mitchell  <mark@codesourcery.com>

        PR c++/11332
        * typeck.c (build_static_cast): Avoid returning expressions with
        reference type.

and

2003-06-25  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10990
	* search.c (lookup_base_r): Rely on accessible_p, rather than
	trying to emulate that logic here.

        PR c++/10931
        * call.c (convert_like): Pass issue_conversion_warnings.
        (convert_like_with_context): Likewise.
        (convert_like_real): Add issue_conversion_warnings parameter.
        (perform_direct_initialization_if_possible): New function.
        * cp-tree.h (perform_direct_initialization_if_possible): Declare it.
        * typeck.c (check_for_casting_away_constness): New function.
        (build_static_cast): Rewrite.

Looking at the backtrace, the patch most likely causing this
problem is the search.c change.

Mark, OK to assign this one to you?
Comment 7 CVS Commits 2003-07-14 05:13:01 UTC
Subject: Bug 11503

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-07-14 05:12:57

Modified files:
	gcc/cp         : ChangeLog class.c cp-tree.h pt.c search.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: anon1.C 

Log message:
	PR c++/11503
	* g++.dg/template/anon1.C: New test.
	
	PR c++/11503
	* cp-tree.h (DECL_SELF_REFERENCE_P): New macro.
	(SET_DECL_SELF_REFERENCE_P): Likewise.
	* class.c (build_self_reference): Use SET_DECL_SELF_REFERENCE_P.
	* pt.c (tsubst_decl): Copy it.
	* search.c (lookup_base): Use DECL_SELF_REFERENCE_P.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3515&r2=1.3516
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.551&r2=1.552
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.874&r2=1.875
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.722&r2=1.723
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.274&r2=1.275
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2870&r2=1.2871
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/anon1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 CVS Commits 2003-07-14 05:18:15 UTC
Subject: Bug 11503

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-07-14 05:18:09

Modified files:
	gcc/cp         : class.c cp-tree.h pt.c search.c 
Added files:
	gcc/testsuite/g++.dg/template: anon1.C 

Log message:
	PR c++/11503
	* g++.dg/template/anon1.C: New test.
	
	PR c++/11503
	* cp-tree.h (DECL_SELF_REFERENCE_P): New macro.
	(SET_DECL_SELF_REFERENCE_P): Likewise.
	* class.c (build_self_reference): Use SET_DECL_SELF_REFERENCE_P.
	* pt.c (tsubst_decl): Copy it.
	* search.c (lookup_base): Use DECL_SELF_REFERENCE_P.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.15&r2=1.499.2.16
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.25&r2=1.776.2.26
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.31&r2=1.635.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.243.2.13&r2=1.243.2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/anon1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 9 CVS Commits 2003-07-14 05:20:19 UTC
Subject: Bug 11503

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-07-14 05:20:17

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 

Log message:
	PR c++/11503
	* g++.dg/template/anon1.C: New test.
	
	PR c++/11503
	* cp-tree.h (DECL_SELF_REFERENCE_P): New macro.
	(SET_DECL_SELF_REFERENCE_P): Likewise.
	* class.c (build_self_reference): Use SET_DECL_SELF_REFERENCE_P.
	* pt.c (tsubst_decl): Copy it.
	* search.c (lookup_base): Use DECL_SELF_REFERENCE_P.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.181&r2=1.3076.2.182
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.229&r2=1.2261.2.230

Comment 10 Mark Mitchell 2003-07-14 05:21:41 UTC
Fixed in GCC 3.3.1 and GCC 3.4.