/* Type based alias analysis.
- Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
- Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010
+ Free Software Foundation, Inc.
Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
This file is part of GCC.
previous cases above. During the analysis phase, a bit is set in
one of these vectors if an operation of the offending class is
discovered to happen on the associated type. */
-
+
static bitmap global_types_exposed_parameter;
static bitmap global_types_full_escape;
static bitmap_obstack ipa_obstack;
-/* Static functions from this file that are used
+/* Static functions from this file that are used
before being defined. */
static unsigned int look_for_casts (tree);
static bool is_cast_from_non_pointer (tree, gimple, void *);
get_name_of_type (tree type)
{
tree name = TYPE_NAME (type);
-
+
if (!name)
/* Unnamed type, do what you like here. */
return "<UNNAMED>";
-
+
/* It will be a TYPE_DECL in the case of a typedef, otherwise, an
identifier_node */
if (TREE_CODE (name) == TYPE_DECL)
}
else if (TREE_CODE (name) == IDENTIFIER_NODE)
return IDENTIFIER_POINTER (name);
- else
+ else
return "<UNNAMED>";
}
-struct type_brand_s
+struct type_brand_s
{
const char* name;
int seq;
/* Splay tree comparison function on type_brand_s structures. */
-static int
+static int
compare_type_brand (splay_tree_key sk1, splay_tree_key sk2)
{
struct type_brand_s * k1 = (struct type_brand_s *) sk1;
int value = strcmp(k1->name, k2->name);
if (value == 0)
return k2->seq - k1->seq;
- else
+ else
return value;
}
case VECTOR_TYPE:
case VOID_TYPE:
return true;
-
+
default:
return false;
}
the POINTER_TOs and if SEE_THRU_ARRAYS is true, remove all of the
ARRAY_OFs and POINTER_TOs. */
-static tree
+static tree
get_canon_type (tree type, bool see_thru_ptrs, bool see_thru_arrays)
{
splay_tree_node result;
return NULL;
type = TYPE_MAIN_VARIANT (type);
- if (see_thru_arrays)
+ if (see_thru_arrays)
while (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
- else if (see_thru_ptrs)
+ else if (see_thru_ptrs)
while (POINTER_TYPE_P (type))
type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
result = splay_tree_lookup (type_to_canon_type, (splay_tree_key) type);
-
+
if (result == NULL)
return discover_unique_type (type);
else return (tree) result->value;
number if TYPE is a pointer to a record or union. The number is
the number of pointer types stripped to get to the record or union
type. Return -1 if TYPE is none of the above. */
-
+
int
-ipa_type_escape_star_count_of_interesting_type (tree type)
+ipa_type_escape_star_count_of_interesting_type (tree type)
{
int count = 0;
/* Strip the *'s off. */
}
/* We are interested in records, and unions only. */
- if (TREE_CODE (type) == RECORD_TYPE
- || TREE_CODE (type) == QUAL_UNION_TYPE
+ if (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == QUAL_UNION_TYPE
|| TREE_CODE (type) == UNION_TYPE)
return count;
- else
+ else
return -1;
-}
+}
/* Return 0 if TYPE is a record or union type. Return a positive
number if TYPE is a pointer to a record or union. The number is
the number of pointer types stripped to get to the record or union
type. Return -1 if TYPE is none of the above. */
-
+
int
-ipa_type_escape_star_count_of_interesting_or_array_type (tree type)
+ipa_type_escape_star_count_of_interesting_or_array_type (tree type)
{
int count = 0;
/* Strip the *'s off. */
}
/* We are interested in records, and unions only. */
- if (TREE_CODE (type) == RECORD_TYPE
- || TREE_CODE (type) == QUAL_UNION_TYPE
+ if (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == QUAL_UNION_TYPE
|| TREE_CODE (type) == UNION_TYPE)
return count;
- else
+ else
return -1;
-}
-
-
+}
+
+
/* Return true if the record, or union TYPE passed in escapes this
compilation unit. Note that all of the pointer-to's are removed
before testing since these may not be correct. */
{
if (!initialized)
return false;
- return !bitmap_bit_p (global_types_full_escape,
+ return !bitmap_bit_p (global_types_full_escape,
get_canon_type_uid (type, true, false));
}
/* Return true if a modification to a field of type FIELD_TYPE cannot
clobber a record of RECORD_TYPE. */
-bool
+bool
ipa_type_escape_field_does_not_clobber_p (tree record_type, tree field_type)
-{
+{
splay_tree_node result;
int uid;
-
+
if (!initialized)
return false;
while (POINTER_TYPE_P (record_type))
{
record_type = TYPE_MAIN_VARIANT (TREE_TYPE (record_type));
- if (POINTER_TYPE_P (field_type))
+ if (POINTER_TYPE_P (field_type))
field_type = TYPE_MAIN_VARIANT (TREE_TYPE (field_type));
- else
+ else
/* However, if field_type is a union, this quick test is not
correct since one of the variants of the union may be a
pointer to type and we cannot see across that here. So we
just strip the remaining pointer tos off the record type
and fall thru to the more precise code. */
- if (TREE_CODE (field_type) == QUAL_UNION_TYPE
+ if (TREE_CODE (field_type) == QUAL_UNION_TYPE
|| TREE_CODE (field_type) == UNION_TYPE)
{
while (POINTER_TYPE_P (record_type))
record_type = TYPE_MAIN_VARIANT (TREE_TYPE (record_type));
break;
- }
- else
+ }
+ else
return true;
}
-
+
record_type = get_canon_type (record_type, true, true);
/* The record type must be contained. The field type may
escape. */
uid = TYPE_UID (record_type);
result = splay_tree_lookup (uid_to_addressof_down_map, (splay_tree_key) uid);
-
- if (result)
+
+ if (result)
{
bitmap field_type_map = (bitmap) result->value;
uid = get_canon_type_uid (field_type, true, true);
int uid;
type = get_canon_type (type, true, true);
- if (!type)
+ if (!type)
return NULL;
- switch (escape_status)
+ switch (escape_status)
{
case EXPOSED_PARAMETER:
map = global_types_exposed_parameter;
/* Efficiency hack. When things are bad, do not mess around
with this type anymore. */
bitmap_set_bit (global_types_exposed_parameter, uid);
- }
+ }
}
return type;
}
EXPOSED_PARAMETER and the TYPE is a pointer type, the set is
changed to FULL_ESCAPE. */
-static void
+static void
mark_interesting_type (tree type, enum escape_t escape_status)
{
if (!type) return;
/* Return true if PARENT is supertype of CHILD. Both types must be
known to be structures or unions. */
-
+
static bool
parent_type_p (tree parent, tree child)
{
int i;
tree binfo, base_binfo;
- if (TYPE_BINFO (parent))
+ if (TYPE_BINFO (parent))
for (binfo = TYPE_BINFO (parent), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
tree binfotype = BINFO_TYPE (base_binfo);
- if (binfotype == child)
+ if (binfotype == child)
return true;
else if (parent_type_p (binfotype, child))
return true;
}
if (TREE_CODE (parent) == UNION_TYPE
- || TREE_CODE (parent) == QUAL_UNION_TYPE)
+ || TREE_CODE (parent) == QUAL_UNION_TYPE)
{
tree field;
/* Search all of the variants in the union to see if one of them
tree field_type;
if (TREE_CODE (field) != FIELD_DECL)
continue;
-
+
field_type = TREE_TYPE (field);
- if (field_type == child)
+ if (field_type == child)
return true;
}
tree field_type;
if (TREE_CODE (field) != FIELD_DECL)
continue;
-
+
field_type = TREE_TYPE (field);
- if (TREE_CODE (field_type) == RECORD_TYPE
- || TREE_CODE (field_type) == QUAL_UNION_TYPE
+ if (TREE_CODE (field_type) == RECORD_TYPE
+ || TREE_CODE (field_type) == QUAL_UNION_TYPE
|| TREE_CODE (field_type) == UNION_TYPE)
- if (parent_type_p (field_type, child))
+ if (parent_type_p (field_type, child))
return true;
}
}
-
+
if (TREE_CODE (parent) == RECORD_TYPE)
{
tree field;
tree field_type;
if (TREE_CODE (field) != FIELD_DECL)
continue;
-
+
field_type = TREE_TYPE (field);
- if (field_type == child)
+ if (field_type == child)
return true;
/* You can only cast to the first field so if it does not
match, quit. */
- if (TREE_CODE (field_type) == RECORD_TYPE
- || TREE_CODE (field_type) == QUAL_UNION_TYPE
+ if (TREE_CODE (field_type) == RECORD_TYPE
+ || TREE_CODE (field_type) == QUAL_UNION_TYPE
|| TREE_CODE (field_type) == UNION_TYPE)
{
- if (parent_type_p (field_type, child))
+ if (parent_type_p (field_type, child))
return true;
- else
+ else
break;
}
}
/* Return the number of pointer tos for TYPE and return TYPE with all
of these stripped off. */
-static int
+static int
count_stars (tree* type_ptr)
{
tree type = *type_ptr;
{
int to_stars = count_stars (&to_type);
int from_stars = count_stars (&from_type);
- if (to_stars != from_stars)
+ if (to_stars != from_stars)
return CT_SIDEWAYS;
if (to_type == from_type)
if (parent_type_p (to_type, from_type)) return CT_UP;
if (parent_type_p (from_type, to_type)) return CT_DOWN;
return CT_SIDEWAYS;
-}
+}
-/* This function returns nonzero if VAR is result of call
+/* This function returns nonzero if VAR is result of call
to malloc function. */
static bool
if (!var)
return false;
-
+
if (SSA_NAME_IS_DEFAULT_DEF (var))
return false;
def_stmt = SSA_NAME_DEF_STMT (var);
-
+
if (!is_gimple_call (def_stmt))
return false;
/* Check a cast FROM this variable, TO_TYPE. Mark the escaping types
if appropriate. Returns cast_type as detected. */
-
+
static enum cast_type
-check_cast (tree to_type, tree from)
+check_cast (tree to_type, tree from)
{
tree from_type = get_canon_type (TREE_TYPE (from), false, false);
bool to_interesting_type, from_interesting_type;
if (!from_type || !to_type || from_type == to_type)
return cast;
- to_interesting_type =
+ to_interesting_type =
ipa_type_escape_star_count_of_interesting_type (to_type) >= 0;
- from_interesting_type =
+ from_interesting_type =
ipa_type_escape_star_count_of_interesting_type (from_type) >= 0;
- if (to_interesting_type)
+ if (to_interesting_type)
if (from_interesting_type)
{
/* Both types are interesting. This can be one of four types
interesting here because if type is marked as escaping, all
of its subtypes escape. */
cast = check_cast_type (to_type, from_type);
- switch (cast)
+ switch (cast)
{
case CT_UP:
case CT_USELESS:
else
{
/* This code excludes two cases from marking as escaped:
-
+
1. if this is a cast of index of array of structures/unions
- that happens before accessing array element, we should not
+ that happens before accessing array element, we should not
mark it as escaped.
2. if this is a cast from the local that is a result from a
- call to malloc, do not mark the cast as bad.
+ call to malloc, do not mark the cast as bad.
*/
-
+
if (POINTER_TYPE_P (to_type) && !POINTER_TYPE_P (from_type))
cast = CT_FROM_NON_P;
- else if (TREE_CODE (from) == SSA_NAME
+ else if (TREE_CODE (from) == SSA_NAME
&& is_malloc_result (from))
cast = CT_FROM_MALLOC;
else
cast = CT_NO_CAST;
return cast;
-}
+}
-typedef struct cast
+typedef struct cast
{
int type;
gimple stmt;
} cast_t;
-/* This function is a callback for walk_use_def_chains function called
+/* This function is a callback for walk_use_def_chains function called
from is_array_access_through_pointer_and_index. */
static bool
{
if (!def_stmt || !var)
return false;
-
+
if (gimple_code (def_stmt) == GIMPLE_PHI)
return false;
if (is_gimple_assign (def_stmt))
{
- use_operand_p use_p;
+ use_operand_p use_p;
ssa_op_iter iter;
unsigned int cast = look_for_casts_stmt (def_stmt);
/* Check that only one cast happened, and it's of non-pointer
type. */
- if ((cast & CT_FROM_NON_P) == (CT_FROM_NON_P)
+ if ((cast & CT_FROM_NON_P) == (CT_FROM_NON_P)
&& (cast & ~(CT_FROM_NON_P)) == 0)
{
((cast_t *)data)->stmt = def_stmt;
is_cast_from_non_pointer, data, false);
if (((cast_t*)data)->type == -1)
break;
- }
+ }
}
/* The cast is harmful. */
else
((cast_t *)data)->type = -1;
- }
+ }
if (((cast_t*)data)->type == -1)
return true;
-
+
return false;
}
-/* When array element a_p[i] is accessed through the pointer a_p
+/* When array element a_p[i] is accessed through the pointer a_p
and index i, it's translated into the following sequence
in gimple:
a_p.2_8 = a_p;
D.1608_9 = D.1606_7 + a_p.2_8;
- OP0 and OP1 are of the same pointer types and stand for
+ OP0 and OP1 are of the same pointer types and stand for
D.1606_7 and a_p.2_8 or vise versa.
This function checks that:
- 1. one of OP0 and OP1 (D.1606_7) has passed only one cast from
+ 1. one of OP0 and OP1 (D.1606_7) has passed only one cast from
non-pointer type (D.1606_7 = (struct str_t *) D.1605_6;).
- 2. one of OP0 and OP1 which has passed the cast from
- non-pointer type (D.1606_7), is actually generated by multiplication of
+ 2. one of OP0 and OP1 which has passed the cast from
+ non-pointer type (D.1606_7), is actually generated by multiplication of
index by size of type to which both OP0 and OP1 point to
(in this case D.1605_6 = i.1_5 * 16; ).
- 3. an address of def of the var to which was made cast (D.1605_6)
+ 3. an address of def of the var to which was made cast (D.1605_6)
was not taken.(How can it happen?)
The following items are checked implicitly by the end of algorithm:
- 4. one of OP0 and OP1 (a_p.2_8) have never been cast
- (because if it was cast to pointer type, its type, that is also
- the type of OP0 and OP1, will be marked as escaped during
- analysis of casting stmt (when check_cast() is called
- from scan_for_refs for this stmt)).
+ 4. one of OP0 and OP1 (a_p.2_8) have never been cast
+ (because if it was cast to pointer type, its type, that is also
+ the type of OP0 and OP1, will be marked as escaped during
+ analysis of casting stmt (when check_cast() is called
+ from scan_for_refs for this stmt)).
5. defs of OP0 and OP1 are not passed into externally visible function
(because if they are passed then their type, that is also the type of OP0
- and OP1, will be marked and escaped during check_call function called from
+ and OP1, will be marked and escaped during check_call function called from
scan_for_refs with call stmt).
- In total, 1-5 guaranty that it's an access to array by pointer and index.
+ In total, 1-5 guaranty that it's an access to array by pointer and index.
*/
bool
-is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
+is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
tree op1, tree *base, tree *offset,
gimple *offset_cast_stmt)
{
false);
pointer_set_destroy (visited_stmts);
- visited_stmts = pointer_set_create ();
+ visited_stmts = pointer_set_create ();
walk_use_def_chains (op1, is_cast_from_non_pointer,(void *)(&op1_cast),
false);
pointer_set_destroy (visited_stmts);
else if (op0_cast.type == 0 && op1_cast.type == 1)
{
*base = op0;
- *offset = op1;
+ *offset = op1;
*offset_cast_stmt = op1_cast.stmt;
}
else
return false;
}
-
- /* Check 2.
- offset_cast_stmt is of the form:
+
+ /* Check 2.
+ offset_cast_stmt is of the form:
D.1606_7 = (struct str_t *) D.1605_6; */
if (*offset_cast_stmt)
before_cast = SINGLE_SSA_TREE_OPERAND (*offset_cast_stmt, SSA_OP_USE);
if (!before_cast)
return false;
-
+
if (SSA_NAME_IS_DEFAULT_DEF (before_cast))
return false;
-
+
before_cast_def_stmt = SSA_NAME_DEF_STMT (before_cast);
if (!before_cast_def_stmt)
return false;
/* before_cast_def_stmt should be of the form:
D.1605_6 = i.1_5 * 16; */
-
+
if (is_gimple_assign (before_cast_def_stmt))
{
/* We expect temporary here. */
{
tree arg0 = gimple_assign_rhs1 (before_cast_def_stmt);
tree arg1 = gimple_assign_rhs2 (before_cast_def_stmt);
- tree unit_size =
+ tree unit_size =
TYPE_SIZE_UNIT (TREE_TYPE (TYPE_MAIN_VARIANT (TREE_TYPE (op0))));
- if (!(CONSTANT_CLASS_P (arg0)
+ if (!(CONSTANT_CLASS_P (arg0)
&& simple_cst_equal (arg0, unit_size))
- && !(CONSTANT_CLASS_P (arg1)
+ && !(CONSTANT_CLASS_P (arg1)
&& simple_cst_equal (arg1, unit_size)))
- return false;
+ return false;
}
else
return false;
/* Register the parameter and return types of function FN. The type
ESCAPES if the function is visible outside of the compilation
unit. */
-static void
-check_function_parameter_and_return_types (tree fn, bool escapes)
+static void
+check_function_parameter_and_return_types (tree fn, bool escapes)
{
tree arg;
-
+
if (TYPE_ARG_TYPES (TREE_TYPE (fn)))
{
for (arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
if (escapes)
{
tree type = get_canon_type (TREE_TYPE (TREE_TYPE (fn)), false, false);
- mark_interesting_type (type, EXPOSED_PARAMETER);
+ mark_interesting_type (type, EXPOSED_PARAMETER);
}
}
tree type = get_canon_type (TREE_TYPE (t), false, false);
if (!type) return;
- if (lookup_attribute ("used", DECL_ATTRIBUTES (t)))
+ if (DECL_PRESERVE_P (t))
{
mark_interesting_type (type, FULL_ESCAPE);
return;
/* Do not want to do anything with volatile except mark any
function that uses one to be not const or pure. */
- if (TREE_THIS_VOLATILE (t))
+ if (TREE_THIS_VOLATILE (t))
return;
/* Do not care about a local automatic that is not static. */
constant, we can allow this variable in pure or const
functions but the scope is too large for our analysis to set
these bits ourselves. */
-
+
if (TREE_READONLY (t)
&& DECL_INITIAL (t)
&& is_gimple_min_invariant (DECL_INITIAL (t)))
; /* Read of a constant, do not change the function state. */
- else
+ else
{
/* The type escapes for all public and externs. */
mark_interesting_type (type, FULL_ESCAPE);
check_function_parameter_and_return_types (t, true);
else if (TREE_CODE (t) == VAR_DECL)
- has_proper_scope_for_analysis (t);
+ has_proper_scope_for_analysis (t);
}
/* Examine tree T for references. */
int from_uid;
int to_uid;
bitmap type_map;
- splay_tree_node result;
+ splay_tree_node result;
from_type = get_canon_type (from_type, false, false);
to_type = get_canon_type (to_type, false, false);
-
+
if (!from_type || !to_type)
return;
to_uid = TYPE_UID (to_type);
gcc_assert (ipa_type_escape_star_count_of_interesting_type (from_type) == 0);
-
+
/* Process the Y into X map pointer. */
- result = splay_tree_lookup (uid_to_addressof_down_map,
+ result = splay_tree_lookup (uid_to_addressof_down_map,
(splay_tree_key) from_uid);
-
- if (result)
- type_map = (bitmap) result->value;
- else
+
+ if (result)
+ type_map = (bitmap) result->value;
+ else
{
type_map = BITMAP_ALLOC (&ipa_obstack);
splay_tree_insert (uid_to_addressof_down_map,
- from_uid,
+ from_uid,
(splay_tree_value)type_map);
}
bitmap_set_bit (type_map, TYPE_UID (to_type));
-
+
/* Process the X into Y reverse map pointer. */
- result =
+ result =
splay_tree_lookup (uid_to_addressof_up_map, (splay_tree_key) to_uid);
-
- if (result)
- type_map = (bitmap) result->value;
- else
+
+ if (result)
+ type_map = (bitmap) result->value;
+ else
{
type_map = BITMAP_ALLOC (&ipa_obstack);
splay_tree_insert (uid_to_addressof_up_map,
- to_uid,
+ to_uid,
(splay_tree_value)type_map);
}
- bitmap_set_bit (type_map, TYPE_UID (from_type));
+ bitmap_set_bit (type_map, TYPE_UID (from_type));
}
/* Scan tree T to see if there are any addresses taken in within T. */
-static void
+static void
look_for_address_of (tree t)
{
if (TREE_CODE (t) == ADDR_EXPR)
tree cref = TREE_OPERAND (t, 0);
/* If we have an expression of the form "&a.b.c.d", mark a.b,
- b.c and c.d. as having its address taken. */
+ b.c and c.d. as having its address taken. */
tree fielddecl = NULL_TREE;
while (cref!= x)
{
if (TREE_CODE (cref) == COMPONENT_REF)
{
fielddecl = TREE_OPERAND (cref, 1);
- mark_interesting_addressof (TREE_TYPE (fielddecl),
+ mark_interesting_addressof (TREE_TYPE (fielddecl),
DECL_FIELD_CONTEXT (fielddecl));
}
else if (TREE_CODE (cref) == ARRAY_REF)
cref = TREE_OPERAND (cref, 0);
}
- if (TREE_CODE (x) == VAR_DECL)
+ if (TREE_CODE (x) == VAR_DECL)
has_proper_scope_for_analysis (x);
}
}
/* Scan tree T to see if there are any casts within it. */
-static unsigned int
+static unsigned int
look_for_casts (tree t)
{
unsigned int cast = 0;
tree castfromvar = TREE_OPERAND (t, 0);
cast = cast | check_cast (TREE_TYPE (t), castfromvar);
}
- else
+ else
while (handled_component_p (t))
{
t = TREE_OPERAND (t, 0);
if (!cast)
cast = CT_NO_CAST;
return cast;
-}
+}
/* Check to see if T is a read or address of operation on a static var
we are interested in analyzing. */
for (i = 0; i < gimple_asm_ninputs (stmt); i++)
check_rhs_var (gimple_asm_input_op (stmt, i));
-
+
/* There is no code here to check for asm memory clobbers. The
casual maintainer might think that such code would be necessary,
but that appears to be wrong. In other parts of the compiler,
for (i = 0; i < gimple_call_num_args (call); i++)
check_rhs_var (gimple_call_arg (call, i));
-
+
if (callee_t)
{
tree arg_type;
tree last_arg_type = NULL;
callee = cgraph_node(callee_t);
avail = cgraph_function_body_availability (callee);
-
+
/* Check that there are no implicit casts in the passing of
parameters. */
if (TYPE_ARG_TYPES (TREE_TYPE (callee_t)))
{
for (arg_type = TYPE_ARG_TYPES (TREE_TYPE (callee_t)), i = 0;
- arg_type && TREE_VALUE (arg_type) != void_type_node;
+ arg_type && TREE_VALUE (arg_type) != void_type_node
+ && i < gimple_call_num_args (call);
arg_type = TREE_CHAIN (arg_type), i++)
{
tree operand = gimple_call_arg (call, i);
last_arg_type = TREE_VALUE(arg_type);
check_cast (last_arg_type, operand);
}
- else
+ else
/* The code reaches here for some unfortunate
builtin functions that do not have a list of
argument types. */
- break;
+ break;
}
- }
- else
- {
+ }
+ else
+ {
/* FIXME - According to Geoff Keating, we should never
have to do this; the front ends should always process
the arg list from the TYPE_ARG_LIST. */
for (arg_type = DECL_ARGUMENTS (callee_t), i = 0;
- arg_type;
+ arg_type && i < gimple_call_num_args (call);
arg_type = TREE_CHAIN (arg_type), i++)
{
tree operand = gimple_call_arg (call, i);
{
last_arg_type = TREE_TYPE (arg_type);
check_cast (last_arg_type, operand);
- }
- else
+ }
+ else
/* The code reaches here for some unfortunate
builtin functions that do not have a list of
argument types. */
- break;
+ break;
}
}
-
+
/* In the case where we have a var_args function, we need to
check the remaining parameters against the last argument. */
arg_type = last_arg_type;
tree operand = gimple_call_arg (call, i);
if (arg_type)
check_cast (arg_type, operand);
- else
+ else
{
/* The code reaches here for some unfortunate
builtin functions that do not have a list of
tree type = get_canon_type (TREE_TYPE (operand), false, false);
mark_interesting_type (type, EXPOSED_PARAMETER);
}
-
- if (callee_t)
+
+ if (callee_t)
{
- tree type =
+ tree type =
get_canon_type (TREE_TYPE (TREE_TYPE (callee_t)), false, false);
mark_interesting_type (type, EXPOSED_PARAMETER);
}
/* CODE is the operation on OP0 and OP1. OP0 is the operand that we
*know* is a pointer type. OP1 may be a pointer type. */
-static bool
+static bool
okay_pointer_operation (enum tree_code code, tree op0, tree op1)
{
tree op0type = TYPE_MAIN_VARIANT (TREE_TYPE (op0));
gimple offset_cast_stmt;
if (POINTER_TYPE_P (op0type)
- && TREE_CODE (op0) == SSA_NAME
- && TREE_CODE (op1) == SSA_NAME
- && is_array_access_through_pointer_and_index (code, op0, op1,
- &base,
- &offset,
+ && TREE_CODE (op0) == SSA_NAME
+ && TREE_CODE (op1) == SSA_NAME
+ && is_array_access_through_pointer_and_index (code, op0, op1,
+ &base,
+ &offset,
&offset_cast_stmt))
return true;
else
{
tree size_of_op0_points_to = TYPE_SIZE_UNIT (TREE_TYPE (op0type));
-
+
if (CONSTANT_CLASS_P (op1)
&& size_of_op0_points_to
- && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
+ && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
op1, size_of_op0_points_to))
return true;
- if (CONSTANT_CLASS_P (op0)
+ if (CONSTANT_CLASS_P (op0)
&& size_of_op0_points_to
- && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
+ && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
op0, size_of_op0_points_to))
- return true;
+ return true;
}
}
break;
/* Next check the operands on the rhs to see if they are ok. */
switch (TREE_CODE_CLASS (gimple_assign_rhs_code (t)))
{
- case tcc_binary:
+ case tcc_binary:
{
tree op0 = gimple_assign_rhs1 (t);
tree type0 = get_canon_type (TREE_TYPE (op0), false, false);
static void
scan_for_refs (gimple t)
{
- switch (gimple_code (t))
+ switch (gimple_code (t))
{
case GIMPLE_ASSIGN:
check_assign (t);
break;
- case GIMPLE_CALL:
+ case GIMPLE_CALL:
/* If this is a call to malloc, squirrel away the result so we
do mark the resulting cast as being bad. */
check_call (t);
break;
-
+
case GIMPLE_ASM:
check_asm (t);
break;
-
+
default:
break;
}
/* The init routine for analyzing global static variable usage. See
comments at top for description. */
-static void
-ipa_init (void)
+static void
+ipa_init (void)
{
bitmap_obstack_initialize (&ipa_obstack);
global_types_exposed_parameter = BITMAP_ALLOC (&ipa_obstack);
compilation unit but their right hand sides may contain references
to variables defined within this unit. */
-static void
+static void
analyze_variable (struct varpool_node *vnode)
{
tree global = vnode->decl;
analyze_function (struct cgraph_node *fn)
{
tree decl = fn->decl;
- check_function_parameter_and_return_types (decl,
+ check_function_parameter_and_return_types (decl,
fn->local.externally_visible);
if (dump_file)
fprintf (dump_file, "\n local analysis of %s", cgraph_node_name (fn));
-
+
{
struct function *this_cfun = DECL_STRUCT_FUNCTION (decl);
basic_block this_block;
step = TREE_CHAIN (step))
{
tree var = TREE_VALUE (step);
- if (TREE_CODE (var) == VAR_DECL
+ if (TREE_CODE (var) == VAR_DECL
&& DECL_INITIAL (var)
&& !TREE_STATIC (var))
check_tree (DECL_INITIAL (var));
static tree
type_for_uid (int uid)
{
- splay_tree_node result =
+ splay_tree_node result =
splay_tree_lookup (uid_to_canon_type, (splay_tree_key) uid);
-
+
if (result)
- return (tree) result->value;
+ return (tree) result->value;
else return NULL;
}
/* Return a bitmap with the subtypes of the type for UID. If it
does not exist, return either NULL or a new bitmap depending on the
- value of CREATE. */
+ value of CREATE. */
static bitmap
subtype_map_for_uid (int uid, bool create)
{
- splay_tree_node result = splay_tree_lookup (uid_to_subtype_map,
+ splay_tree_node result = splay_tree_lookup (uid_to_subtype_map,
(splay_tree_key) uid);
-
- if (result)
- return (bitmap) result->value;
+
+ if (result)
+ return (bitmap) result->value;
else if (create)
{
bitmap subtype_map = BITMAP_ALLOC (&ipa_obstack);
splay_tree_insert (uid_to_subtype_map,
- uid,
+ uid,
(splay_tree_value)subtype_map);
return subtype_map;
}
/* If we are doing a language with a type hierarchy, mark all of
the superclasses. */
- if (TYPE_BINFO (type))
+ if (TYPE_BINFO (type))
for (binfo = TYPE_BINFO (type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
tree binfo_type = BINFO_TYPE (base_binfo);
- bitmap subtype_map = subtype_map_for_uid
+ bitmap subtype_map = subtype_map_for_uid
(TYPE_UID (TYPE_MAIN_VARIANT (binfo_type)), true);
bitmap_set_bit (subtype_map, uid);
close_type_seen (get_canon_type (binfo_type, true, true));
}
-
+
/* If the field is a struct or union type, mark all of the
subfields. */
for (field = TYPE_FIELDS (type);
/* Take a TYPE that has been passed by value to an external function
and mark all of the fields that have pointer types as escaping. For
any of the non pointer types that are structures or unions,
- recurse. TYPE is never a pointer type. */
+ recurse. TYPE is never a pointer type. */
static void
close_type_exposed_parameter (tree type)
mark_interesting_type (field_type, EXPOSED_PARAMETER);
/* Only recurse for non pointer types of structures and unions. */
- if (ipa_type_escape_star_count_of_interesting_type (field_type) == 0)
+ if (ipa_type_escape_star_count_of_interesting_type (field_type) == 0)
close_type_exposed_parameter (field_type);
}
}
/* The next function handles the case where a type fully escapes.
- This means that not only does the type itself escape,
+ This means that not only does the type itself escape,
a) the type of every field recursively escapes
b) the type of every subtype escapes as well as the super as well
Take a TYPE that has had the address taken for an instance of it
and mark all of the types for its fields as having their addresses
- taken. */
+ taken. */
static void
close_type_full_escape (tree type)
tree binfo, base_binfo;
bitmap_iterator bi;
bitmap subtype_map;
- splay_tree_node address_result;
+ splay_tree_node address_result;
/* Strip off any pointer or array types. */
type = get_canon_type (type, true, true);
/* If we are doing a language with a type hierarchy, mark all of
the superclasses. */
- if (TYPE_BINFO (type))
+ if (TYPE_BINFO (type))
for (binfo = TYPE_BINFO (type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
binfotype = mark_type (binfotype, FULL_ESCAPE);
close_type_full_escape (binfotype);
}
-
+
/* Mark as escaped any types that have been down casted to
this type. */
if (subtype_map)
EXECUTE_IF_SET_IN_BITMAP (subtype_map, 0, i, bi)
{
- tree subtype = type_for_uid (i);
+ tree subtype = type_for_uid (i);
subtype = mark_type (subtype, FULL_ESCAPE);
close_type_full_escape (subtype);
}
/* For all of the types A that contain this type B and were part of
an expression like "&...A.B...", mark the A's as escaping. */
- address_result = splay_tree_lookup (uid_to_addressof_up_map,
+ address_result = splay_tree_lookup (uid_to_addressof_up_map,
(splay_tree_key) uid);
if (address_result)
{
/* Transitively close the addressof bitmap for the type with UID.
This means that if we had a.b and b.c, a would have both b and c in
- its maps. */
+ its maps. */
static bitmap
-close_addressof_down (int uid)
+close_addressof_down (int uid)
{
bitmap_iterator bi;
- splay_tree_node result =
+ splay_tree_node result =
splay_tree_lookup (uid_to_addressof_down_map, (splay_tree_key) uid);
bitmap map = NULL;
bitmap new_map;
unsigned int i;
-
- if (result)
+
+ if (result)
map = (bitmap) result->value;
- else
+ else
return NULL;
if (bitmap_bit_p (been_there_done_that, uid))
{
bitmap submap = close_addressof_down (i);
bitmap_set_bit (new_map, i);
- if (submap)
+ if (submap)
bitmap_ior_into (new_map, submap);
- }
+ }
result->value = (splay_tree_value) new_map;
BITMAP_FREE (map);
We do not want to process any of the clones so we check that this
is a master clone. However, we do need to process any
AVAIL_OVERWRITABLE functions (these are never clones) because
- they may cause a type variable to escape.
+ they may cause a type variable to escape.
*/
for (node = cgraph_nodes; node; node = node->next)
- if (node->analyzed)
+ if (node->analyzed && !node->clone_of)
analyze_function (node);
contained an entry for Y if there had been an operation of the
form &X.Y. This step adds all of the fields contained within Y
(recursively) to X's map. */
-
+
result = splay_tree_min (uid_to_addressof_down_map);
while (result)
{
{
tree type = (tree) result->value;
tree key = (tree) result->key;
- if (POINTER_TYPE_P (type)
+ if (POINTER_TYPE_P (type)
|| TREE_CODE (type) == ARRAY_TYPE)
{
splay_tree_remove (all_canon_types, (splay_tree_key) result->key);
}
if (dump_file)
- {
+ {
EXECUTE_IF_SET_IN_BITMAP (global_types_seen, 0, i, bi)
{
/* The pointer types are in the global_types_full_escape
print_generic_expr (dump_file, type, 0);
if (bitmap_bit_p (global_types_full_escape, i))
fprintf(dump_file, " escaped\n");
- else
+ else
fprintf(dump_file, " contained\n");
}
}