Commit 54c93c30 by Ansgar Esztermann Committed by Richard Henderson

c-typeck.c (c_tree_expr_nonnegative_p): New function.

        * c-typeck.c (c_tree_expr_nonnegative_p): New function.
	(build_binary_op): Call c_tree_expr_nonnegative_p rather than
	tree_expr_nonnegative_p.
	(build_conditional_expr): Likewise.
        * c-tree.h (c_tree_expr_nonnegative_p): Declare.

        * gcc.dg/compare2.c: Remove xfail from cases 10 and 12.

From-SVN: r56927
parent 3aa4cad7
2002-09-07 Ansgar Esztermann <ansgar@thphy.uni-duesseldorf.de>
* c-typeck.c (c_tree_expr_nonnegative_p): New function.
(build_binary_op): Call c_tree_expr_nonnegative_p rather than
tree_expr_nonnegative_p.
(build_conditional_expr): Likewise.
* c-tree.h (c_tree_expr_nonnegative_p): Declare.
2002-09-07 Richard Henderson <rth@redhat.com>
* builtins.def (inf, inff, infl): Mark const.
......
......@@ -268,6 +268,7 @@ extern tree build_array_ref PARAMS ((tree, tree));
extern tree build_external_ref PARAMS ((tree, int));
extern tree parser_build_binary_op PARAMS ((enum tree_code,
tree, tree));
extern int c_tree_expr_nonnegative_p PARAMS ((tree));
extern void readonly_warning PARAMS ((tree, const char *));
extern tree build_conditional_expr PARAMS ((tree, tree, tree));
extern tree build_compound_expr PARAMS ((tree));
......
......@@ -2463,7 +2463,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
constant expression involving such literals or a
conditional expression involving such literals)
and it is non-negative. */
if (tree_expr_nonnegative_p (sop))
if (c_tree_expr_nonnegative_p (sop))
/* OK */;
/* Do not warn if the comparison is an equality operation,
the unsigned quantity is an integral constant, and it
......@@ -2579,6 +2579,27 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
}
}
/* Return true if `t' is known to be non-negative. */
int
c_tree_expr_nonnegative_p (t)
tree t;
{
if (TREE_CODE (t) == STMT_EXPR)
{
t=COMPOUND_BODY (STMT_EXPR_STMT (t));
/* Find the last statement in the chain, ignoring the final
* scope statement */
while (TREE_CHAIN (t) != NULL_TREE
&& TREE_CODE (TREE_CHAIN (t)) != SCOPE_STMT)
t=TREE_CHAIN (t);
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
}
return tree_expr_nonnegative_p (t);
}
/* Return a tree for the difference of pointers OP0 and OP1.
The resulting tree has type int. */
......@@ -3406,8 +3427,8 @@ build_conditional_expr (ifexp, op1, op2)
/* Do not warn if the signed quantity is an unsuffixed
integer literal (or some static constant expression
involving such literals) and it is non-negative. */
else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
|| (unsigned_op1 && tree_expr_nonnegative_p (op2)))
else if ((unsigned_op2 && c_tree_expr_nonnegative_p (op1))
|| (unsigned_op1 && c_tree_expr_nonnegative_p (op2)))
/* OK */;
else
warning ("signed and unsigned type in conditional expression");
......
2002-09-07 Ansgar Esztermann <ansgar@thphy.uni-duesseldorf.de>
* gcc.dg/compare2.c: Remove xfail from cases 10 and 12.
2002-09-05 Ziemowit Laski <zlaski@apple.com>
* objc.dg/proto-lossage-1.m: New test.
......
......@@ -26,11 +26,11 @@ void f(int x, unsigned int y)
/* Statement expression. */
x > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 9" } */
y > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 10" { xfail *-*-* } } */
y > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 10" } */
/* Statement expression with recursive ?: . */
x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 11" } */
y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 12" { xfail *-*-* } } */
y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 12" } */
/* Statement expression with signed ?:. */
x > ({tf; tf?64:-1;}); /* { dg-bogus "signed and unsigned" "case 13" } */
......
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