Bug 25632 - [4.0 Regression] ICE with const int copied into two different functions
Summary: [4.0 Regression] ICE with const int copied into two different functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P1 critical
Target Milestone: 4.0.3
Assignee: Zdenek Dvorak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, monitored, patch
: 25921 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-02 10:37 UTC by Richard Biener
Modified: 2006-02-28 17:39 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.1 4.1.0 4.2.0
Known to fail: 4.0.3
Last reconfirmed: 2006-01-02 16:36:18


Attachments
reduced testcase (519 bytes, text/plain)
2006-01-02 10:38 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-01-02 10:37:58 UTC
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.
Comment 1 Richard Biener 2006-01-02 10:38:35 UTC
Created attachment 10575 [details]
reduced testcase

testcase
Comment 2 Andrew Pinski 2006-01-02 16:36:18 UTC
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;
}
Comment 3 Mark Mitchell 2006-01-03 00:24:21 UTC
ICE on valid, plausible code.
Comment 4 Zdenek Dvorak 2006-01-03 11:31:15 UTC
Adding unshare_expr to constant_value_1 fixes the problem, but causes bootstrap failure.
Comment 5 Andrew Pinski 2006-01-03 14:12:10 UTC
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.
Comment 6 Zdenek Dvorak 2006-01-03 22:40:18 UTC
Patch:

http://gcc.gnu.org/ml/gcc-patches/2006-01/msg00136.html
Comment 7 Mark Mitchell 2006-01-03 23:01:05 UTC
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?

Comment 8 Zdenek Dvorak 2006-01-03 23:24:55 UTC
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.
Comment 9 Zdenek Dvorak 2006-01-03 23:29:14 UTC
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
Comment 10 Mark Mitchell 2006-01-04 00:01:27 UTC
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;".

Comment 11 Mark Mitchell 2006-01-04 00:02:14 UTC
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
> 
> 


Comment 12 Zdenek Dvorak 2006-01-04 22:46:14 UTC
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

Comment 13 Zdenek Dvorak 2006-01-05 00:29:38 UTC
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

Comment 14 Andrew Pinski 2006-01-05 14:29:27 UTC
Fixed at least on the 4.1 branch and the mainline.  Zdenek can you add the reduced testcase in comment #2?
Comment 15 Zdenek Dvorak 2006-01-11 11:39:54 UTC
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

Comment 16 Andrew Pinski 2006-01-23 14:31:33 UTC
*** Bug 25921 has been marked as a duplicate of this bug. ***
Comment 17 Mark Mitchell 2006-02-27 20:21:34 UTC
Zdenek, does your patch apply to 4.0?
Comment 18 Zdenek Dvorak 2006-02-28 00:18:43 UTC
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.
Comment 19 Mark Mitchell 2006-02-28 00:25:45 UTC
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!

Comment 20 Zdenek Dvorak 2006-02-28 14:24:10 UTC
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

Comment 21 Andrew Pinski 2006-02-28 17:39:35 UTC
Fixed.