static int require_constant_value;
static int require_constant_elements;
+static bool null_pointer_constant_p (tree);
static tree qualify_type (tree, tree);
static int tagged_types_tu_compatible_p (tree, tree);
static int comp_target_types (tree, tree);
static int lvalue_p (tree);
static void record_maybe_used_decl (tree);
static int comptypes_internal (tree, tree);
+\f
+/* Return true if EXP is a null pointer constant, false otherwise. */
+
+static bool
+null_pointer_constant_p (tree expr)
+{
+ /* This should really operate on c_expr structures, but they aren't
+ yet available everywhere required. */
+ tree type = TREE_TYPE (expr);
+ return (TREE_CODE (expr) == INTEGER_CST
+ && !TREE_CONSTANT_OVERFLOW (expr)
+ && integer_zerop (expr)
+ && (INTEGRAL_TYPE_P (type)
+ || (TREE_CODE (type) == POINTER_TYPE
+ && VOID_TYPE_P (TREE_TYPE (type))
+ && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
+}
\f/* This is a cache to hold if two types are compatible or not. */
struct tagged_tu_seen_cache {
{
if (comp_target_types (type1, type2))
result_type = common_pointer_type (type1, type2);
- else if (integer_zerop (orig_op1) && TREE_TYPE (type1) == void_type_node)
+ else if (null_pointer_constant_p (orig_op1))
result_type = qualify_type (type2, type1);
- else if (integer_zerop (orig_op2) && TREE_TYPE (type2) == void_type_node)
+ else if (null_pointer_constant_p (orig_op2))
result_type = qualify_type (type1, type2);
else if (VOID_TYPE_P (TREE_TYPE (type1)))
{
}
else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
{
- if (!integer_zerop (op2))
+ if (!null_pointer_constant_p (orig_op2))
pedwarn ("pointer/integer type mismatch in conditional expression");
else
{
}
else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
{
- if (!integer_zerop (op1))
+ if (!null_pointer_constant_p (orig_op1))
pedwarn ("pointer/integer type mismatch in conditional expression");
else
{
&& TREE_CODE (otype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
- && !(integer_zerop (value) && TREE_TYPE (otype) == void_type_node))
+ && !null_pointer_constant_p (value))
pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
ovalue = value;
}
/* Can convert integer zero to any pointer type. */
- if (integer_zerop (rhs))
+ if (null_pointer_constant_p (rhs))
{
rhs = null_pointer_node;
break;
&& ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
||
(VOID_TYPE_P (ttr)
- && !integer_zerop (rhs)
+ && !null_pointer_constant_p (rhs)
&& TREE_CODE (ttl) == FUNCTION_TYPE)))
WARN_FOR_ASSIGNMENT (G_("ISO C forbids passing argument %d of "
"%qE between function pointer "
/* An explicit constant 0 can convert to a pointer,
or one that results from arithmetic, even including
a cast to integer type. */
- if (!integer_zerop (rhs))
+ if (!null_pointer_constant_p (rhs))
WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
"pointer from integer without a cast"),
G_("assignment makes pointer from integer "
{
/* op0 != orig_op0 detects the case of something
whose value is 0 but which isn't a valid null ptr const. */
- if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
+ if (pedantic && !null_pointer_constant_p (orig_op0)
&& TREE_CODE (tt1) == FUNCTION_TYPE)
pedwarn ("ISO C forbids comparison of %<void *%>"
" with function pointer");
}
else if (VOID_TYPE_P (tt1))
{
- if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
+ if (pedantic && !null_pointer_constant_p (orig_op1)
&& TREE_CODE (tt0) == FUNCTION_TYPE)
pedwarn ("ISO C forbids comparison of %<void *%>"
" with function pointer");
if (result_type == NULL_TREE)
result_type = ptr_type_node;
}
- else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
- && integer_zerop (op1))
+ else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
result_type = type0;
- else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
- && integer_zerop (op0))
+ else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
result_type = type1;
else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
{
pedwarn ("comparison of distinct pointer types lacks a cast");
}
}
- else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
- && integer_zerop (op1))
+ else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
{
result_type = type0;
if (pedantic || extra_warnings)
pedwarn ("ordered comparison of pointer with integer zero");
}
- else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
- && integer_zerop (op0))
+ else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
{
result_type = type1;
if (pedantic)