When investigating PR 40464 I have come across a declaration with DECL_HAS_VALUE_EXPR_P and DECL_VALUE_EXPR set (which indeed turned out to be the root of the problem). However, according to a comment in tree.h: "once this field has been set, the decl itself may not legitimately appear in the function." Richard Guenther has written a patch to verify there are none such declarations in the function statements and found none on an x86_64 (and so did I). However, when I run the test on a hppa I got over two hundred failures in the c testsuite alone. The patch is at http://gcc.gnu.org/ml/gcc-patches/2009-08/msg00419.html Steps to reproduce: 1) apply the patch above, 2) compile gcc (probably irrespective of configuration but see below) and 3) run the c testsuite. For the sake of completeness, I have configured gcc with: /home/jamborm/gcc/trunk/configure --prefix=/home/jamborm/gcc/inst/trunk/ --enable-checking=yes --enable-languages=c,c++ --disable-bootstrap --with-mpfr=/opt/cfarm/mpfr-2.3.2/ --disable-multilib
We have discussed this in the mailing list thread that eventually lead to http://gcc.gnu.org/ml/gcc-patches/2009-09/msg00374.html The bottom line is that we two options: 1) Do not set DECL_VALUE_EXPR to callee copied parameters in gimplify_parameters() and represent the convention explicitely. I have tested this preliminary by running the c testsuite (no bootstrap or some such thing) and so far found no ICEs or miscompilations. The drawback is that this approach will most probably mess up debug info and the link in between the original and actual parameter will get lost. The benefit is that we would uphold the stated (but currently violated) rule that declarations with the DECL_VALUE_EXPR do not occur in the function body. 2) The second approach is to teach gimplifier not to do the substitutions which can be bogus. Once the function body has been gimplifed, we might set some flag in the gimplification context or, alternatively, I'm about to try to simply disable the substitutions in gimplify_var_or_parm_decl() for PARM_DECLs. This would mean we would need to drop the rule not allowing such decls in the function body. I don't know whether it needs to be replaced by some weaker restriction.
I ran into too many problems when I tried to inhibit value_expr PARM_DECL substitutions in the gimplifier. At the moment I believe we should not use the value_expr just for debug info and rather try BLOCK_NONLOCALIZED_VARS from pretty-ipa. I've just sent an email about this to the gcc mailing list: http://gcc.gnu.org/ml/gcc/2009-09/msg00218.html
On IRC, Jakub told me to remove the value_expr flag after gimplification and to introduce a new dummy var decl with the flag set for the purpose of debugging. My first attempt is the following patch. It did bootstrap on the hppa we have on the compile farm (over the weekend :-) and the testsuite seem to have only one new regression (g++.dg/inherit/thunk6.C). I am about to do a non-bootstrap build to examine that as well as the debug info performance now. Nevertheless, I'll be grateful for any comments even at this stage, expecially regarding attributes that need to be (or should not be) copied to the new dummy declaration. Those dealt with in the patch are from copy_var_decl() in omp-low.c (which I did not call directly because it sets DECL_SEEN_IN_BIND_EXPR_P). 2009-10-05 Martin Jambor <mjambor@suse.cz> PR middle-end/41250 * function.c (fixup_value_expr_parm_decls): New function. * tree.h (fixup_value_expr_parm_decls): Declare. * gimplify.c (gimplify_body): Call fixup_value_expr_parm_decls. Index: small/gcc/function.c =================================================================== --- small.orig/gcc/function.c +++ small/gcc/function.c @@ -3438,6 +3438,31 @@ gimplify_parameters (void) return stmts; } + +/* Remove DECL_HAS_VALUE_EXPR_P flag from parameters so that that such + declarations do not occur in the IL. */ + +void +fixup_value_expr_parm_decls (void) +{ + tree parm, fnargs = DECL_ARGUMENTS (current_function_decl); + + for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) + if (DECL_HAS_VALUE_EXPR_P (parm)) + { + tree copy = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL, + DECL_NAME (parm), TREE_TYPE (parm)); + DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (parm); + DECL_IGNORED_P (copy) = DECL_IGNORED_P (parm); + DECL_CONTEXT (copy) = DECL_CONTEXT (parm); + TREE_USED (copy) = 1; + SET_DECL_VALUE_EXPR (copy, DECL_VALUE_EXPR (parm)); + DECL_HAS_VALUE_EXPR_P (copy) = 1; + + DECL_HAS_VALUE_EXPR_P (parm) = 0; + DECL_IGNORED_P (parm) = 1; + } +} /* Compute the size and offset from the start of the stacked arguments for a parm passed in mode PASSED_MODE and with type TYPE. Index: small/gcc/gimplify.c =================================================================== --- small.orig/gcc/gimplify.c +++ small/gcc/gimplify.c @@ -7482,6 +7482,7 @@ gimplify_body (tree *body_p, tree fndecl { gimplify_seq_add_seq (&parm_stmts, gimple_bind_body (outer_bind)); gimple_bind_set_body (outer_bind, parm_stmts); + fixup_value_expr_parm_decls (); } if (nonlocal_vlas) Index: small/gcc/tree.h =================================================================== --- small.orig/gcc/tree.h +++ small/gcc/tree.h @@ -4994,6 +4994,7 @@ extern int aggregate_value_p (const_tree extern void push_function_context (void); extern void pop_function_context (void); extern gimple_seq gimplify_parameters (void); +extern void fixup_value_expr_parm_decls (void); /* In print-rtl.c */ #ifdef BUFSIZ
Was the patch from comment #3 ever sent to gcc-patches? I couldn't find it. I did see earlier discussions about some other patches but the patch in comment #3 seems to have been put here after those discussions. I tested it on my hppa2.0w-hp-hpux11.11 system and it fixed g++.dg/torture/pr34099.C and did not cause any regressions.
Mine.
*** Bug 42805 has been marked as a duplicate of this bug. ***
Fixed.
Subject: Bug 41250 Author: rguenth Date: Mon Mar 1 15:43:32 2010 New Revision: 157148 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157148 Log: 2010-03-01 Richard Guenther <rguenther@suse.de> Martin Jambor <mjambor@suse.cz> PR middle-end/41250 * gimplify.c (gimplify_body): Unset DECL_HAS_VALUE_EXPR_P on gimplified parameters. Modified: trunk/gcc/ChangeLog trunk/gcc/gimplify.c