This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Refine escaping pointers when integers are involved
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: dnovillo at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 26 Nov 04 19:54:28 EST
- Subject: Refine escaping pointers when integers are involved
This fixes ACATS test cxa5012. The issue is that the act of converting a
pointer value to an integer type means that pointer escapes. The special
case of detecting taking the address of something and assigning it to an
integer-typed variable is too special. You might, for example, be converting
a pointer, not an ADDR_EXPR, to an integer.
Do you agree with this patch?
Tested on x86_64-linux-gnu.
2004-11-26 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* tree-ssa-alias.c (compute_points_to_and_addr_escapes): Remove
special code for assigning to non-pointer.
(is_escape_site): If RHS is a conversion between pointer and integer
types, this is an escape site.
*** tree-ssa-alias.c 19 Nov 2004 02:38:25 -0000 2.55
--- tree-ssa-alias.c 24 Nov 2004 14:55:09 -0000
*************** tree global_var;
*** 196,200 ****
a pointer or an ADDR_EXPR escapes, it means that it has been exposed
outside of the current function. So, assignment to global variables,
! function arguments and returning a pointer are all escape sites.
This is where we are currently limited. Since not everything is renamed
--- 196,201 ----
a pointer or an ADDR_EXPR escapes, it means that it has been exposed
outside of the current function. So, assignment to global variables,
! function arguments and returning a pointer are all escape sites, as are
! conversions between pointers and integers.
This is where we are currently limited. Since not everything is renamed
*************** compute_points_to_and_addr_escape (struc
*** 607,626 ****
block_ann->has_escape_site = 1;
- /* Special case for silly ADDR_EXPR tricks
- (gcc.c-torture/unsorted/pass.c). If this statement is an
- assignment to a non-pointer variable and the RHS takes the
- address of a variable, assume that the variable on the RHS is
- call-clobbered. We could add the LHS to the list of
- "pointers" and follow it to see if it really escapes, but it's
- not worth the pain. */
- if (addr_taken
- && TREE_CODE (stmt) == MODIFY_EXPR
- && !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (stmt, 0))))
- EXECUTE_IF_SET_IN_BITMAP (addr_taken, 0, i, bi)
- {
- tree var = referenced_var (i);
- mark_call_clobbered (var);
- }
-
FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
{
--- 608,611 ----
*************** is_escape_site (tree stmt, size_t *num_c
*** 1992,1995 ****
--- 1985,1998 ----
return true;
+ /* If the RHS is a conversion between a pointer and an integer, the
+ pointer escapes since we can't track the integer. */
+ if ((TREE_CODE (TREE_OPERAND (stmt, 1)) == NOP_EXPR
+ || TREE_CODE (TREE_OPERAND (stmt, 1)) == CONVERT_EXPR
+ || TREE_CODE (TREE_OPERAND (stmt, 1)) == VIEW_CONVERT_EXPR)
+ && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND
+ (TREE_OPERAND (stmt, 1), 0)))
+ && !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (stmt, 1))))
+ return true;
+
/* If the LHS is an SSA name, it can't possibly represent a non-local
memory store. */