GNU C++ version 4.1.0 20051221 (prerelease) ICEs on the attached testcase with > g++ nvl141082.min.i /suse/rguenther/export/nvl141082.min.i: In function ‘SI_RETURN SiGetPeerName(SI_SOCK*, SAP_RAW*, SAP_USHORT*)’: /suse/rguenther/export/nvl141082.min.i:48: internal compiler error: in make_decl_rtl, at varasm.c:890 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://www.suse.de/feedback> for instructions.
Created attachment 10575 [details] reduced testcase testcase
Reduced testcase (even though it gives a different ICE, it is the same bug as someone is forgetting to unshare_expr somewhere): struct sockaddr_un { char sun_path[1]; }; const unsigned SI_SUN_HEAD_LEN = (long)(((struct sockaddr_un *)0)->sun_path); int SiGetPeerName () { return SI_SUN_HEAD_LEN; } int SiAccept () { return SI_SUN_HEAD_LEN; }
ICE on valid, plausible code.
Adding unshare_expr to constant_value_1 fixes the problem, but causes bootstrap failure.
Caused by either: 2005-10-16 Mark Mitchell <mark@codesourcery.com> PR c++/24389 * decl2.c (mark_used): Use uses_template_parms instead of dependent_type_p. * init.c (constant_value_1): Handle uninstantiated templates specially. * pt.c (instantiate_decl): Add sanity check. or 2005-10-11 Mark Mitchell <mark@codesourcery.com> PR c++/21089 * call.c (convert_like_real): Use decl_constant_value, not integral_constant_value. * init.c (constant_value_1): New function. (integral_constant_value): Use it. (decl_constant_value): Likewise. * typeck.c (decay_conversion): Use decl_constant_value, not integral_constant_value.
Patch: http://gcc.gnu.org/ml/gcc-patches/2006-01/msg00136.html
Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied into two different functions rakdver at gcc dot gnu dot org wrote: > ------- Comment #6 from rakdver at gcc dot gnu dot org 2006-01-03 22:40 ------- > Patch: > > http://gcc.gnu.org/ml/gcc-patches/2006-01/msg00136.html This patch is not OK, but it's close. We should not call unshare_expr on DECL_INITIAL until after the mark_used call, as static data members in templates will not have proper initializers until after that point. Also, there's no need to unshare *before* calling fold_non_dependent_expr. In fact, there's no need to unshare before the return statement at the end of the function. That will avoid creating trees that will only be thrown away later. So, why not just do: return unshare_expr (decl); at the end of the function?
Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied into two different functions > ------- Comment #7 from mark at codesourcery dot com 2006-01-03 23:01 ------- > Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied > into two different functions > > rakdver at gcc dot gnu dot org wrote: > > ------- Comment #6 from rakdver at gcc dot gnu dot org 2006-01-03 22:40 ------- > > Patch: > > > > http://gcc.gnu.org/ml/gcc-patches/2006-01/msg00136.html > > This patch is not OK, but it's close. > > We should not call unshare_expr on DECL_INITIAL until after the > mark_used call, as static data members in templates will not have proper > initializers until after that point. Also, there's no need to unshare > *before* calling fold_non_dependent_expr. > > In fact, there's no need to unshare before the return statement at the > end of the function. That will avoid creating trees that will only be > thrown away later. > > So, why not just do: > > return unshare_expr (decl); > > at the end of the function? because that causes bootstrap failure -- fold_decl_constant_value does tree const_expr = expr; do { expr = fold_non_dependent_expr (const_expr); const_expr = integral_constant_value (expr); } while (expr != const_expr); and if constant_value_1 (called by integral_constant_value) unshares the expression unconditionally (not only when it processes DECL_INITIAL), this loop never ends.
Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied into two different functions > rakdver at gcc dot gnu dot org wrote: > > ------- Comment #6 from rakdver at gcc dot gnu dot org 2006-01-03 22:40 ------- > > Patch: > > > > http://gcc.gnu.org/ml/gcc-patches/2006-01/msg00136.html > > This patch is not OK, but it's close. > > We should not call unshare_expr on DECL_INITIAL until after the > mark_used call, as static data members in templates will not have proper > initializers until after that point. Also, there's no need to unshare > *before* calling fold_non_dependent_expr. > > In fact, there's no need to unshare before the return statement at the > end of the function. That will avoid creating trees that will only be > thrown away later. what about this patch, then (assuming it passes testing)? Index: cp/init.c =================================================================== *** cp/init.c (revision 109271) --- cp/init.c (working copy) *************** constant_value_1 (tree decl, bool integr *** 1503,1508 **** --- 1503,1510 ---- mark_used (decl); init = DECL_INITIAL (decl); } + init = unshare_expr (init); + if (!(init || init == error_mark_node) || !TREE_TYPE (init) || (integral_p
Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied into two different functions rakdver at atrey dot karlin dot mff dot cuni dot cz wrote: > tree const_expr = expr; > do > { > expr = fold_non_dependent_expr (const_expr); > const_expr = integral_constant_value (expr); > } > while (expr != const_expr); > > and if constant_value_1 (called by integral_constant_value) unshares the > expression unconditionally (not only when it processes DECL_INITIAL), > this loop never ends. OK; then call unshare_expr after the "break" statement in constant_value_1, and before "decl = init;".
Subject: Re: [4.0/4.1/4.2 Regression] ICE with const int copied into two different functions rakdver at atrey dot karlin dot mff dot cuni dot cz wrote: > what about this patch, then (assuming it passes testing)? Better -- but there's no reason to do it before the break statement; if we're not going to use init, then we don't neeed to unshare it. I think you can do it right *after* the break statement. > Index: cp/init.c > =================================================================== > *** cp/init.c (revision 109271) > --- cp/init.c (working copy) > *************** constant_value_1 (tree decl, bool integr > *** 1503,1508 **** > --- 1503,1510 ---- > mark_used (decl); > init = DECL_INITIAL (decl); > } > + init = unshare_expr (init); > + > if (!(init || init == error_mark_node) > || !TREE_TYPE (init) > || (integral_p > >
Subject: Bug 25632 Author: rakdver Date: Wed Jan 4 22:46:09 2006 New Revision: 109354 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109354 Log: PR c++/25632 * init.c (constant_value_1): Unshare use of DECL_INITIAL. Fix a typo in condition. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/init.c
Subject: Bug 25632 Author: rakdver Date: Thu Jan 5 00:29:34 2006 New Revision: 109369 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109369 Log: PR c++/25632 * init.c (constant_value_1): Unshare use of DECL_INITIAL. Fix a typo in condition. Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/init.c
Fixed at least on the 4.1 branch and the mainline. Zdenek can you add the reduced testcase in comment #2?
Subject: Bug 25632 Author: rakdver Date: Wed Jan 11 11:39:49 2006 New Revision: 109575 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109575 Log: PR c++/25632 * g++.dg/other/pr25632.C: New test. Added: trunk/gcc/testsuite/g++.dg/other/pr25632.C Modified: trunk/gcc/testsuite/ChangeLog
*** Bug 25921 has been marked as a duplicate of this bug. ***
Zdenek, does your patch apply to 4.0?
Subject: Re: [4.0 Regression] ICE with const int copied into two different functions > Zdenek, does your patch apply to 4.0? yes, it does.
Subject: Re: [4.0 Regression] ICE with const int copied into two different functions rakdver at atrey dot karlin dot mff dot cuni dot cz wrote: > ------- Comment #18 from rakdver at atrey dot karlin dot mff dot cuni dot cz 2006-02-28 00:18 ------- > Subject: Re: [4.0 Regression] ICE with const int copied into two different > functions > >> Zdenek, does your patch apply to 4.0? > > yes, it does. OK, would you please test and apply, then? Thanks!
Subject: Bug 25632 Author: rakdver Date: Tue Feb 28 14:24:05 2006 New Revision: 111565 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111565 Log: PR c++/25632 * init.c (constant_value_1): Unshare use of DECL_INITIAL. * g++.dg/other/pr25632.C: New test. Added: branches/gcc-4_0-branch/gcc/testsuite/g++.dg/other/pr25632.C Modified: branches/gcc-4_0-branch/gcc/ChangeLog branches/gcc-4_0-branch/gcc/cp/init.c branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
Fixed.