This is the mail archive of the gcc-patches@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]

[PATCH] Fix malloc attribute mishandling


As we now handle malloc results more precise we forget to consider
constructors with malloc attribute.  This causes some perl testcases
to fail.

Fixed as follows -- note this pessimizes simple malloc wrappers again,
we probably need another attribute for more strict semantics (thus,
the returned memory doesn't point to anything, but is either
uninitialized or zero-initialized).  Not that this pessimization
would be a regression to 4.4 (but it is to previous 4.5 snapshots).

Bootstrap and regtest running on x86_64-unknown-linux-gnu, will apply
if that succeeds.

Richard.


2010-02-09  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43008
	* tree-ssa-structalias.c (handle_lhs_call): Pass in the fndecl,
	make HEAP variables initialized from global memory if they
	are not known builtin functions.
	(find_func_aliases): Adjust.

	* gcc.c-torture/execute/pr43008.c: New testcase.

Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c	(revision 156620)
--- gcc/tree-ssa-structalias.c	(working copy)
*************** handle_rhs_call (gimple stmt, VEC(ce_s,
*** 3482,3488 ****
     the LHS point to global and escaped variables.  */
  
  static void
! handle_lhs_call (tree lhs, int flags, VEC(ce_s, heap) *rhsc)
  {
    VEC(ce_s, heap) *lhsc = NULL;
  
--- 3482,3488 ----
     the LHS point to global and escaped variables.  */
  
  static void
! handle_lhs_call (tree lhs, int flags, VEC(ce_s, heap) *rhsc, tree fndecl)
  {
    VEC(ce_s, heap) *lhsc = NULL;
  
*************** handle_lhs_call (tree lhs, int flags, VE
*** 3496,3501 ****
--- 3496,3507 ----
           it escapes.  */
        DECL_EXTERNAL (vi->decl) = 0;
        vi->is_global_var = 0;
+       /* If this is not a real malloc call assume the memory was
+          initialized and thus may point to global memory.  All
+ 	 builtin functions with the malloc attribute behave in a sane way.  */
+       if (!fndecl
+ 	  || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+ 	make_constraint_from (vi, nonlocal_id);
      }
    else if (VEC_length (ce_s, rhsc) > 0)
      {
*************** find_func_aliases (gimple origt)
*** 3798,3804 ****
  	    handle_rhs_call (t, &rhsc);
  	  if (gimple_call_lhs (t)
  	      && could_have_pointers (gimple_call_lhs (t)))
! 	    handle_lhs_call (gimple_call_lhs (t), flags, rhsc);
  	  VEC_free (ce_s, heap, rhsc);
  	}
        else
--- 3804,3810 ----
  	    handle_rhs_call (t, &rhsc);
  	  if (gimple_call_lhs (t)
  	      && could_have_pointers (gimple_call_lhs (t)))
! 	    handle_lhs_call (gimple_call_lhs (t), flags, rhsc, fndecl);
  	  VEC_free (ce_s, heap, rhsc);
  	}
        else
Index: gcc/testsuite/gcc.c-torture/execute/pr43008.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr43008.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr43008.c	(revision 0)
***************
*** 0 ****
--- 1,23 ----
+ int i;
+ struct X {
+   int *p;
+ };
+ struct X * __attribute__((malloc))
+ my_alloc (void)
+ {
+   struct X *p = __builtin_malloc (sizeof (struct X));
+   p->p = &i;
+   return p;
+ }
+ extern void abort (void);
+ int main()
+ {
+   struct X *p, *q;
+   p = my_alloc ();
+   q = my_alloc ();
+   *(p->p) = 1;
+   *(q->p) = 0;
+   if (*(p->p) != 0)
+     abort ();
+   return 0;
+ }


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