---time.cpp--- struct A { long tv_sec; }; class B { public: operator A () const; }; inline B::operator A () const { int sec = 1; A tv = { tv_sec: sec, }; return tv; } void xxx(const B& t) { A tv(t); } ---end of time.cpp--- with gcc-3.3.3 it is ok. can't see whether this is related to PR14203 or not. [kirr@tugrik bug]$ g++340-check -O -Wall -I include -c time.cpp -o time.o time.cpp: In function `void xxx(const B&)': time.cpp:11: internal compiler error: in make_decl_rtl, at varasm.c:752 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. [kirr@tugrik bug]$ g++340-check -v Reading specs from /usr/local/gcc-3.4.0-check/lib/gcc/i686-pc-linux-gnu/3.4.0/specs Configured with: ../gcc-3.4.0/configure --prefix=/usr/local/gcc-3.4.0-check --with-gnu-as --with-gnu-ld --enable-threads=posix --with-arch=i686 --with-tune=pentium4 --enable-__cxa_atexit --enable-languages=c,c++,f77 --enable-checking --disable-nls Thread model: posix gcc version 3.4.0
Confirmed (but I do not have a tree with 3.4.1 in it). But here is the backtrace #4 0x082da8ea in make_decl_rtl (decl=0x40129804, asmspec=0x0) at ../../gcc/varasm.c:756 #5 0x0815e10c in expand_expr_real (exp=0x40129804, target=0x0, tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0) at ../../gcc/expr.c:6403 #6 0x0815f994 in expand_expr_real (exp=0x4012a6cc, target=0x0, tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0) at ../../gcc/expr.c:7593 #7 0x08163c30 in store_field (target=0x4011b930, bitsize=32, bitpos=0, mode=SImode, exp=0x4012a6cc, value_mode=VOIDmode, unsignedp=0, type=0x401246c0, alias_set=0) at ../../gcc/expr.c:5331 #8 0x081664be in store_constructor_field (target=0x4011b930, bitsize=32, bitpos=0, mode=1108532352, exp=0x4012a6cc, type=0x83, cleared=0, alias_set=0) at ../../gcc/expr.c:4524 #9 0x08164f83 in store_constructor (exp=0x4012a654, target=0x4011b930, cleared=0, size=4) at ../../gcc/expr.c:4723 #10 0x0815ecc4 in expand_expr_real (exp=0x4012a654, target=0x4011b930, tmode=SImode, modifier=EXPAND_NORMAL, alt_rtl=0x0) at ../../gcc/expr.c:6872 #11 0x081630df in store_expr (exp=0x4012a654, target=0x4011b900, want_value=0) at ../../gcc/ expr.c:4221 #12 0x081640ab in expand_assignment (to=0x40129798, from=0x4012a654, want_value=0) at ../../ gcc/expr.c:4001 #13 0x082be1ef in expand_decl_init (decl=0x40129798) at ../../gcc/stmt.c:4086 #14 0x080e5061 in emit_local_var (decl=0x40129798) at ../../gcc/c-semantics.c:287 #15 0x080e5c4c in expand_stmt (t=0x4012a4ec) at ../../gcc/c-semantics.c:806 #16 0x080e5b21 in expand_stmt (t=0x4012a488) at ../../gcc/c-semantics.c:826 #17 0x080dea48 in c_expand_expr (exp=0x4012a49c, target=0x0, tmode=SImode, modifier=0, alt_rtl=0x0) at ../../gcc/c-common.c:4105 #18 0x0815afb5 in expand_expr_real (exp=0x4012a49c, target=0x0, tmode=SImode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
Investigating.
I think the problem lies in the C++ front-end. The ICE happens because the tree-inliner inserts a DECL_STMT corresponding to the RESULT_DECL 'tv' when inlining the operator: arg 0 <compound_stmt 0x4024b488 arg 0 <scope_stmt 0x4024b4c4 tree_0 tree_3 arg 0 <block 0x4024c118 used vars <var_decl 0x4024a6c0 this> abstract_origin <function_decl 0x40248a20 operator 1>> chain <decl_stmt 0x4024b4b0 arg 0 <var_decl 0x4024a6c0 this> --> chain <decl_stmt 0x4024b4ec arg 0 <var_decl 0x4024a798 tv> chain <compound_stmt 0x4024b500 tree_1 tree_2 tree_3 arg 0 <scope_stmt 0x4024b514 tree_0 tree_1 arg 0 <block 0x4024c140> chain <compound_stmt 0x4024b528>> Now the VAR_DECL of 'tv' has a constructor as its DECL_INITIAL, and the constructor references the VAR_DECL of 'sec'. But the declaration of 'sec' has not yet been seen so the compiler invokes make_decl_rtl on a automatic variable and aborts on the entry sanity check. I'm not sure how this should work. In the 3.3.x series, the DECL_STMT is not inserted by tree-inline.c:declare_return_variable /* Build the declaration statement if FN does not return an aggregate. */ if (need_return_decl) return build_stmt (DECL_STMT, var); because FN (the operator) is recognized as returning an aggregate. In the 3.4.x series, this is not true because CALL_EXPR_HAS_RETURN_SLOT_ADDR is not set by simplify_aggr_init_exprs_r/simplify_aggr_init_expr (there is no AGGR_INIT_EXPR in the tree). So it would appear that the front-end has optimized away the aggregate-ness of struct A. Maybe the fix is to remove the DECL_INITIAL when the RESULT_DECL is copied to the VAR_DECL in cp_copy_res_decl_for_inlining. Or maybe it is to treat the operator as returning an aggregate like in the 3.3.x series.
Jason, this is a rather severe problem with interactions between NRV and inlining. Would you please take a look at this ASAP?
This is slightly shorter, and still shows the same bug: ---------------------- struct A { int i; }; inline A foo () { int j = 1; A a = { j }; return a; } A tv = foo(); ---------------------- g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc -O2 x.cc: In function `(static initializers for x.cc)': x.cc:5: internal compiler error: in make_decl_rtl, at varasm.c:752 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. W.
Jason, are you going to be able to look at this problem?
*** Bug 16432 has been marked as a duplicate of this bug. ***
: Search converges between 2002-12-14-trunk (#159) and 2002-12-29-trunk (#160).
*** Bug 17054 has been marked as a duplicate of this bug. ***
Jason, this is a problem with NRV, so I've assigned it to you.
Subject: Bug 15461 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: jason@gcc.gnu.org 2004-08-25 05:33:03 Modified files: gcc/cp : ChangeLog tree.c semantics.c Log message: PR c++/16851 * tree.c (stabilize_init): See through a COMPOUND_EXPR. PR c++/15461 * semantics.c (nullify_returns_r): Replace a DECL_STMT for the NRV with an INIT_EXPR. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.152&r2=1.3892.2.153 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/tree.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.360.4.8&r2=1.360.4.9 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.381.4.13&r2=1.381.4.14
Fixed.
Subject: Bug 15461 CVSROOT: /cvs/gcc Module name: gcc Changes by: jason@gcc.gnu.org 2004-08-25 15:16:37 Added files: gcc/testsuite/g++.dg/opt: nrv7.C Log message: PR c++/15461 * semantics.c (nullify_returns_r): Replace a DECL_STMT for the NRV with an INIT_EXPR. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/nrv7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 15461 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: gdr@gcc.gnu.org 2004-09-13 08:39:17 Modified files: gcc/cp : ChangeLog semantics.c Added files: gcc/testsuite/g++.dg/opt: nrv7.C Log message: PR c++/15857 Backport from gcc-3_4-branch 2004-08-24 Jason Merrill <jason@redhat.com> PR c++/15461 * semantics.c (nullify_returns_r): Replace a DECL_STMT for the NRV with an INIT_EXPR. 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.273&r2=1.3076.2.274 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.282.4.6&r2=1.282.4.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/nrv7.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.10.1