Commit 58393038 by Ziemowit Laski Committed by Mike Stump

c-common.h (objc_comptypes): Remove prototype.

        * c-common.h (objc_comptypes): Remove prototype.
        (objc_compare_types): New prototype.
        (objc_volatilized_decl): Likewise.
        (objc_type_quals_match): Likewise.
        * c-decl.c (objc_mark_locals_volatile): Streamline by calling
        objc_volatilize_decl().
        * c-typeck.c (comp_target_types): Remove third parameter; do
        not call objc_comptypes().
        (comptypes): Remove calls to objc_comptypes().
        (build_function_call): Extend compatible prototype check to ObjC.
        (build_conditional_expr): Adjust call to comp_target_types().
        (convert_for_assignment): Call objc_compare_types() instead of
        objc_comptypes(); adjust calls to comp_target_types(); call
        objc_type_quals_match() before issuing qualifier mismatch
        warnings.
        (build_binary_op): Call objc_compare_types() before issuing
        pointer mismatch warnings; adjust calls to
        comp_target_types().
        * stub-objc.c (objc_comptypes): Remove stub.
        (objc_compare_types): New stub.
        (objc_volatilized_decl): Likewise.
        (objc_type_quals_match): Likewise.

From-SVN: r100126
parent 660845bf
2005-05-24 Ziemowit Laski <zlaski@apple.com>
* c-common.h (objc_comptypes): Remove prototype.
(objc_compare_types): New prototype.
(objc_volatilized_decl): Likewise.
(objc_type_quals_match): Likewise.
* c-decl.c (objc_mark_locals_volatile): Streamline by calling
objc_volatilize_decl().
* c-typeck.c (comp_target_types): Remove third parameter; do
not call objc_comptypes().
(comptypes): Remove calls to objc_comptypes().
(build_function_call): Extend compatible prototype check to ObjC.
(build_conditional_expr): Adjust call to comp_target_types().
(convert_for_assignment): Call objc_compare_types() instead of
objc_comptypes(); adjust calls to comp_target_types(); call
objc_type_quals_match() before issuing qualifier mismatch
warnings.
(build_binary_op): Call objc_compare_types() before issuing
pointer mismatch warnings; adjust calls to
comp_target_types().
* stub-objc.c (objc_comptypes): Remove stub.
(objc_compare_types): New stub.
(objc_volatilized_decl): Likewise.
(objc_type_quals_match): Likewise.
2005-05-24 Paolo Carlini <pcarlini@suse.de> 2005-05-24 Paolo Carlini <pcarlini@suse.de>
* config/ia64/ia64intrin.h: Define nothing for C++: * config/ia64/ia64intrin.h: Define nothing for C++:
......
...@@ -877,7 +877,9 @@ extern tree objc_is_class_name (tree); ...@@ -877,7 +877,9 @@ extern tree objc_is_class_name (tree);
extern tree objc_is_object_ptr (tree); extern tree objc_is_object_ptr (tree);
extern void objc_check_decl (tree); extern void objc_check_decl (tree);
extern int objc_is_reserved_word (tree); extern int objc_is_reserved_word (tree);
extern int objc_comptypes (tree, tree, int); extern bool objc_compare_types (tree, tree, int, tree);
extern void objc_volatilize_decl (tree);
extern bool objc_type_quals_match (tree, tree);
extern tree objc_rewrite_function_call (tree, tree); extern tree objc_rewrite_function_call (tree, tree);
extern tree objc_message_selector (void); extern tree objc_message_selector (void);
extern tree objc_lookup_ivar (tree, tree); extern tree objc_lookup_ivar (tree, tree);
......
...@@ -566,25 +566,7 @@ objc_mark_locals_volatile (void *enclosing_blk) ...@@ -566,25 +566,7 @@ objc_mark_locals_volatile (void *enclosing_blk)
scope = scope->outer) scope = scope->outer)
{ {
for (b = scope->bindings; b; b = b->prev) for (b = scope->bindings; b; b = b->prev)
{ objc_volatilize_decl (b->decl);
tree decl = b->decl;
/* Do not mess with variables that are 'static' or (already)
'volatile'. */
if (!TREE_THIS_VOLATILE (decl) && !TREE_STATIC (decl)
&& (TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (decl) == PARM_DECL))
{
TREE_TYPE (decl)
= build_qualified_type (TREE_TYPE (decl),
(TYPE_QUALS (TREE_TYPE (decl))
| TYPE_QUAL_VOLATILE));
TREE_THIS_VOLATILE (decl) = 1;
TREE_SIDE_EFFECTS (decl) = 1;
DECL_REGISTER (decl) = 0;
C_DECL_REGISTER (decl) = 0;
}
}
/* Do not climb up past the current function. */ /* Do not climb up past the current function. */
if (scope->function_body) if (scope->function_body)
......
...@@ -76,7 +76,7 @@ static int require_constant_elements; ...@@ -76,7 +76,7 @@ static int require_constant_elements;
static tree qualify_type (tree, tree); static tree qualify_type (tree, tree);
static int tagged_types_tu_compatible_p (tree, tree); static int tagged_types_tu_compatible_p (tree, tree);
static int comp_target_types (tree, tree, int); static int comp_target_types (tree, tree);
static int function_types_compatible_p (tree, tree); static int function_types_compatible_p (tree, tree);
static int type_lists_compatible_p (tree, tree); static int type_lists_compatible_p (tree, tree);
static tree decl_constant_value_for_broken_optimization (tree); static tree decl_constant_value_for_broken_optimization (tree);
...@@ -711,10 +711,6 @@ comptypes (tree type1, tree type2) ...@@ -711,10 +711,6 @@ comptypes (tree type1, tree type2)
switch (TREE_CODE (t1)) switch (TREE_CODE (t1))
{ {
case POINTER_TYPE: case POINTER_TYPE:
/* We must give ObjC the first crack at comparing pointers, since
protocol qualifiers may be involved. */
if (c_dialect_objc () && (val = objc_comptypes (t1, t2, 0)) >= 0)
break;
/* Do not remove mode or aliasing information. */ /* Do not remove mode or aliasing information. */
if (TYPE_MODE (t1) != TYPE_MODE (t2) if (TYPE_MODE (t1) != TYPE_MODE (t2)
|| TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
...@@ -766,13 +762,8 @@ comptypes (tree type1, tree type2) ...@@ -766,13 +762,8 @@ comptypes (tree type1, tree type2)
break; break;
} }
case RECORD_TYPE:
/* We are dealing with two distinct structs. In assorted Objective-C
corner cases, however, these can still be deemed equivalent. */
if (c_dialect_objc () && objc_comptypes (t1, t2, 0) == 1)
val = 1;
case ENUMERAL_TYPE: case ENUMERAL_TYPE:
case RECORD_TYPE:
case UNION_TYPE: case UNION_TYPE:
if (val != 1 && !same_translation_unit_p (t1, t2)) if (val != 1 && !same_translation_unit_p (t1, t2))
val = tagged_types_tu_compatible_p (t1, t2); val = tagged_types_tu_compatible_p (t1, t2);
...@@ -790,22 +781,14 @@ comptypes (tree type1, tree type2) ...@@ -790,22 +781,14 @@ comptypes (tree type1, tree type2)
} }
/* Return 1 if TTL and TTR are pointers to types that are equivalent, /* Return 1 if TTL and TTR are pointers to types that are equivalent,
ignoring their qualifiers. REFLEXIVE is only used by ObjC - set it ignoring their qualifiers. */
to 1 or 0 depending if the check of the pointer types is meant to
be reflexive or not (typically, assignments are not reflexive,
while comparisons are reflexive).
*/
static int static int
comp_target_types (tree ttl, tree ttr, int reflexive) comp_target_types (tree ttl, tree ttr)
{ {
int val; int val;
tree mvl, mvr; tree mvl, mvr;
/* Give objc_comptypes a crack at letting these types through. */
if ((val = objc_comptypes (ttl, ttr, reflexive)) >= 0)
return val;
/* Do not lose qualifiers on element types of array types that are /* Do not lose qualifiers on element types of array types that are
pointer targets by taking their TYPE_MAIN_VARIANT. */ pointer targets by taking their TYPE_MAIN_VARIANT. */
mvl = TREE_TYPE (ttl); mvl = TREE_TYPE (ttl);
...@@ -2049,13 +2032,8 @@ build_function_call (tree function, tree params) ...@@ -2049,13 +2032,8 @@ build_function_call (tree function, tree params)
If it is not, replace the call by a trap, wrapped up in a compound If it is not, replace the call by a trap, wrapped up in a compound
expression if necessary. This has the nice side-effect to prevent expression if necessary. This has the nice side-effect to prevent
the tree-inliner from generating invalid assignment trees which may the tree-inliner from generating invalid assignment trees which may
blow up in the RTL expander later. blow up in the RTL expander later. */
if (TREE_CODE (function) == NOP_EXPR
??? This doesn't work for Objective-C because objc_comptypes
refuses to compare function prototypes, yet the compiler appears
to build calls that are flagged as invalid by C's comptypes. */
if (!c_dialect_objc ()
&& TREE_CODE (function) == NOP_EXPR
&& TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
&& TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
&& !comptypes (fntype, TREE_TYPE (tem))) && !comptypes (fntype, TREE_TYPE (tem)))
...@@ -3058,7 +3036,7 @@ build_conditional_expr (tree ifexp, tree op1, tree op2) ...@@ -3058,7 +3036,7 @@ build_conditional_expr (tree ifexp, tree op1, tree op2)
} }
else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
{ {
if (comp_target_types (type1, type2, 1)) if (comp_target_types (type1, type2))
result_type = common_pointer_type (type1, type2); result_type = common_pointer_type (type1, type2);
else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
&& TREE_CODE (orig_op1) != NOP_EXPR) && TREE_CODE (orig_op1) != NOP_EXPR)
...@@ -3532,6 +3510,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3532,6 +3510,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
tree rhstype; tree rhstype;
enum tree_code coder; enum tree_code coder;
tree rname = NULL_TREE; tree rname = NULL_TREE;
bool objc_ok = false;
if (errtype == ic_argpass || errtype == ic_argpass_nonproto) if (errtype == ic_argpass || errtype == ic_argpass_nonproto)
{ {
...@@ -3593,14 +3572,35 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3593,14 +3572,35 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
if (coder == ERROR_MARK) if (coder == ERROR_MARK)
return error_mark_node; return error_mark_node;
if (c_dialect_objc ())
{
int parmno;
switch (errtype)
{
case ic_return:
parmno = 0;
break;
case ic_assign:
parmno = -1;
break;
case ic_init:
parmno = -2;
break;
default:
parmno = parmnum;
break;
}
objc_ok = objc_compare_types (type, rhstype, parmno, rname);
}
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
{ {
overflow_warning (rhs); overflow_warning (rhs);
/* Check for Objective-C protocols. This will automatically
issue a warning if there are protocol violations. No need to
use the return value. */
if (c_dialect_objc ())
objc_comptypes (type, rhstype, 0);
return rhs; return rhs;
} }
...@@ -3683,7 +3683,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3683,7 +3683,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
Meanwhile, the lhs target must have all the qualifiers of Meanwhile, the lhs target must have all the qualifiers of
the rhs. */ the rhs. */
if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
|| comp_target_types (memb_type, rhstype, 0)) || comp_target_types (memb_type, rhstype))
{ {
/* If this type won't generate any warnings, use it. */ /* If this type won't generate any warnings, use it. */
if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr) if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
...@@ -3786,7 +3786,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3786,7 +3786,7 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
and vice versa; otherwise, targets must be the same. and vice versa; otherwise, targets must be the same.
Meanwhile, the lhs target must have all the qualifiers of the rhs. */ Meanwhile, the lhs target must have all the qualifiers of the rhs. */
if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
|| (target_cmp = comp_target_types (type, rhstype, 0)) || (target_cmp = comp_target_types (type, rhstype))
|| is_opaque_pointer || is_opaque_pointer
|| (c_common_unsigned_type (mvl) || (c_common_unsigned_type (mvl)
== c_common_unsigned_type (mvr))) == c_common_unsigned_type (mvr)))
...@@ -3814,14 +3814,20 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3814,14 +3814,20 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
&& TREE_CODE (ttl) != FUNCTION_TYPE) && TREE_CODE (ttl) != FUNCTION_TYPE)
{ {
if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)) if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
WARN_FOR_ASSIGNMENT (N_("passing argument %d of %qE discards " {
"qualifiers from pointer target type"), /* Types differing only by the presence of the 'volatile'
N_("assignment discards qualifiers " qualifier are acceptable if the 'volatile' has been added
"from pointer target type"), in by the Objective-C EH machinery. */
N_("initialization discards qualifiers " if (!objc_type_quals_match (ttl, ttr))
"from pointer target type"), WARN_FOR_ASSIGNMENT (N_("passing argument %d of %qE discards "
N_("return discards qualifiers from " "qualifiers from pointer target type"),
"pointer target type")); N_("assignment discards qualifiers "
"from pointer target type"),
N_("initialization discards qualifiers "
"from pointer target type"),
N_("return discards qualifiers from "
"pointer target type"));
}
/* If this is not a case of ignoring a mismatch in signedness, /* If this is not a case of ignoring a mismatch in signedness,
no warning. */ no warning. */
else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
...@@ -3858,12 +3864,15 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, ...@@ -3858,12 +3864,15 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
} }
} }
else else
WARN_FOR_ASSIGNMENT (N_("passing argument %d of %qE from " /* Avoid warning about the volatile ObjC EH puts on decls. */
"incompatible pointer type"), if (!objc_ok)
N_("assignment from incompatible pointer type"), WARN_FOR_ASSIGNMENT (N_("passing argument %d of %qE from "
N_("initialization from incompatible " "incompatible pointer type"),
"pointer type"), N_("assignment from incompatible pointer type"),
N_("return from incompatible pointer type")); N_("initialization from incompatible "
"pointer type"),
N_("return from incompatible pointer type"));
return convert (type, rhs); return convert (type, rhs);
} }
else if (codel == POINTER_TYPE && coder == ARRAY_TYPE) else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
...@@ -7444,6 +7453,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7444,6 +7453,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
/* Nonzero means set RESULT_TYPE to the common type of the args. */ /* Nonzero means set RESULT_TYPE to the common type of the args. */
int common = 0; int common = 0;
/* True means types are compatible as far as ObjC is concerned. */
bool objc_ok;
if (convert_p) if (convert_p)
{ {
op0 = default_conversion (orig_op0); op0 = default_conversion (orig_op0);
...@@ -7473,6 +7485,8 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7473,6 +7485,8 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
if (code0 == ERROR_MARK || code1 == ERROR_MARK) if (code0 == ERROR_MARK || code1 == ERROR_MARK)
return error_mark_node; return error_mark_node;
objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
switch (code) switch (code)
{ {
case PLUS_EXPR: case PLUS_EXPR:
...@@ -7489,7 +7503,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7489,7 +7503,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
/* Subtraction of two similar pointers. /* Subtraction of two similar pointers.
We must subtract them as integers, then divide by object size. */ We must subtract them as integers, then divide by object size. */
if (code0 == POINTER_TYPE && code1 == POINTER_TYPE if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
&& comp_target_types (type0, type1, 1)) && comp_target_types (type0, type1))
return pointer_diff (op0, op1); return pointer_diff (op0, op1);
/* Handle pointer minus int. Just like pointer plus int. */ /* Handle pointer minus int. Just like pointer plus int. */
else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
...@@ -7658,7 +7672,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7658,7 +7672,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
/* Anything compares with void *. void * compares with anything. /* Anything compares with void *. void * compares with anything.
Otherwise, the targets must be compatible Otherwise, the targets must be compatible
and both must be object or both incomplete. */ and both must be object or both incomplete. */
if (comp_target_types (type0, type1, 1)) if (comp_target_types (type0, type1))
result_type = common_pointer_type (type0, type1); result_type = common_pointer_type (type0, type1);
else if (VOID_TYPE_P (tt0)) else if (VOID_TYPE_P (tt0))
{ {
...@@ -7677,7 +7691,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7677,7 +7691,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
" with function pointer"); " with function pointer");
} }
else else
pedwarn ("comparison of distinct pointer types lacks a cast"); /* Avoid warning about the volatile ObjC EH puts on decls. */
if (!objc_ok)
pedwarn ("comparison of distinct pointer types lacks a cast");
if (result_type == NULL_TREE) if (result_type == NULL_TREE)
result_type = ptr_type_node; result_type = ptr_type_node;
...@@ -7710,7 +7726,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7710,7 +7726,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
short_compare = 1; short_compare = 1;
else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
{ {
if (comp_target_types (type0, type1, 1)) if (comp_target_types (type0, type1))
{ {
result_type = common_pointer_type (type0, type1); result_type = common_pointer_type (type0, type1);
if (!COMPLETE_TYPE_P (TREE_TYPE (type0)) if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
......
...@@ -63,11 +63,22 @@ objc_is_reserved_word (tree ARG_UNUSED (ident)) ...@@ -63,11 +63,22 @@ objc_is_reserved_word (tree ARG_UNUSED (ident))
return 0; return 0;
} }
int bool
objc_comptypes (tree ARG_UNUSED (lhs), tree ARG_UNUSED (rhs), objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
int ARG_UNUSED (reflexive)) int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
{
return false;
}
void
objc_volatilize_decl (tree ARG_UNUSED (decl))
{
}
bool
objc_type_quals_match (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp))
{ {
return -1; return false;
} }
tree tree
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment