This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gimplify_parameters


OK, I see what's going on, but also ran into a bug in SRA.

If I remove the call to gimplify_parm_type on the test case from the
PR, it works fine. To see a breakage, it has to become:

int f(int a, struct {int b[a]; int d;} c) { return c.d;}

The following patch fixes the problem you noticed, but there's a problem in
SRA.  SRA feels it can decompose variablely-sized records.  But if it does
that, then it needs to be prepared to gimplify the COMPONENT_REF it makes.
What's happening is that the COMPONENT_REF doesn't have its third operand set
to the DECL_OFFSET value so that value doesn't get marked as used.

Here's the patch I used, instead of what you sent yesterday:

*** tree.h	20 Dec 2004 11:26:28 -0000	1.668
--- tree.h	21 Dec 2004 14:00:04 -0000
*************** struct tree_common GTY(())
*** 367,370 ****
--- 367,371 ----
  	   all decls
  	   all constants
+        TREE_PARM_LOCAL_TYPE in types
  
     unsigned_flag:
*************** extern void tree_operand_check_failed (i
*** 925,928 ****
--- 926,934 ----
  #define TREE_CONSTANT(NODE) (NON_TYPE_CHECK (NODE)->common.constant_flag)
  
+ /* This type is being declared inside a parameter list.  Applies to all
+    _TYPE nodes.  If set and the type is variably sized, we must gimplify
+    those sizes when processing the parameters.  */
+ #define TREE_PARM_LOCAL_TYPE(NODE) (TYPE_CHECK (NODE)->common.constant_flag)
+ 
  /* In a decl (most significantly a FIELD_DECL), means an unsigned field.  */
  #define DECL_UNSIGNED(NODE) (DECL_CHECK (NODE)->common.unsigned_flag)
*** c-decl.c	20 Dec 2004 20:11:17 -0000	1.617
--- c-decl.c	21 Dec 2004 14:00:06 -0000
*************** get_parm_info (bool ellipsis)
*** 4836,4839 ****
--- 4836,4843 ----
  	case RECORD_TYPE:   keyword = "struct"; goto tag;
  	tag:
+ 	  /* Indicate this type is local to the parameter list so that
+ 	     gimplification can be done on anything variable.  */
+ 	  TREE_PARM_LOCAL_TYPE (decl) = 1;
+ 
  	  /* Types may not have tag-names, in which case the type
  	     appears in the bindings list with b->id NULL.  */
*** function.c	19 Dec 2004 04:42:09 -0000	1.593
--- function.c	21 Dec 2004 14:00:08 -0000
*************** gimplify_parameters (void)
*** 3215,3223 ****
  
        /* ??? Once upon a time variable_size stuffed parameter list
! 	 SAVE_EXPRs (amongst others) onto a pending sizes list.  This
! 	 turned out to be less than manageable in the gimple world.
! 	 Now we have to hunt them down ourselves.  */
!       walk_tree_without_duplicates (&data.passed_type,
! 				    gimplify_parm_type, &stmts);
  
        if (!TREE_CONSTANT (DECL_SIZE (parm)))
--- 3215,3228 ----
  
        /* ??? Once upon a time variable_size stuffed parameter list
!        SAVE_EXPRs (amongst others) onto a pending sizes list.  This
!        turned out to be less than manageable in the gimple world.
!        Now we have to hunt them down ourselves.  However, the only
!        time we need to do this is if the parameter's type is defined
!        locally to this parameter list.  Otherwise it's been done by
!        the type being in some DECL_EXPR or it doesn't have to be done
!        (global types in Ada).  */
!       if (TREE_PARM_LOCAL_TYPE (TREE_TYPE (parm)))
! 	walk_tree_without_duplicates (&data.passed_type,
! 				      gimplify_parm_type, &stmts);
  
        if (!TREE_CONSTANT (DECL_SIZE (parm)))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]