This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to elide sign compare warning in ?:
- To: egcs-patches at egcs dot cygnus dot com
- Subject: Patch to elide sign compare warning in ?:
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Fri, 7 Apr 2000 11:44:55 -0400 (EDT)
We already eliminate sign compare warnings for "(unsigned) > 64".
This patch eliminates the sign compare warnings for these kinds of
expressions: "(unsigned) > (foo ? 64 : 32)"
This construct appears a lot on platforms like the sparc-solaris where
BIGGEST_ALIGNMENT is defined as (TARGET_ARCH64 ? 128 : 64), the sign
compare warnings are reduced from 227 to 56. On a platform like
x86-linux where BIGGEST_ALIGNMENT is a constant, the gains are modest,
(something like 2.)
Okay to install?
--Kaveh
PS: Alternate suggestions on what to call the tree_expr_unsigned_p
function would be appreciated. I'm not sure the current name
accurately describes what is does.
2000-04-07 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* tree.c (tree_expr_unsigned_p): New function.
* tree.h (tree_expr_unsigned_p): Declare.
* c-typeck.c (build_binary_op): Call `tree_expr_unsigned_p' to
elide some sign_compare warnings.
cp:
* typeck.c (build_binary_op): Call `tree_expr_unsigned_p' to elide
some sign_compare warnings.
diff -rup orig/egcs-CVS20000405/gcc/tree.c egcs-CVS20000405/gcc/tree.c
--- orig/egcs-CVS20000405/gcc/tree.c Mon Apr 3 22:20:32 2000
+++ egcs-CVS20000405/gcc/tree.c Thu Apr 6 09:15:58 2000
@@ -4370,6 +4370,25 @@ tree_int_cst_sgn (t)
return 1;
}
+/* Return true if `t' is known to be unsigned. */
+
+int
+tree_expr_unsigned_p (t)
+ tree t;
+{
+ switch (TREE_CODE (t))
+ {
+ case INTEGER_CST:
+ return tree_int_cst_sgn (t) >= 0;
+ case COND_EXPR:
+ return tree_expr_unsigned_p (TREE_OPERAND (t, 1))
+ && tree_expr_unsigned_p (TREE_OPERAND (t, 2));
+ default:
+ /* We don't know sign of `t', so be safe and return false. */
+ return 0;
+ }
+}
+
/* Compare two constructor-element-type constants. Return 1 if the lists
are known to be equal; otherwise return 0. */
diff -rup orig/egcs-CVS20000405/gcc/tree.h egcs-CVS20000405/gcc/tree.h
--- orig/egcs-CVS20000405/gcc/tree.h Tue Apr 4 14:18:53 2000
+++ egcs-CVS20000405/gcc/tree.h Thu Apr 6 08:55:48 2000
@@ -1697,6 +1697,7 @@ extern int host_integerp PARAMS ((tree,
extern HOST_WIDE_INT tree_low_cst PARAMS ((tree, int));
extern int tree_int_cst_msb PARAMS ((tree));
extern int tree_int_cst_sgn PARAMS ((tree));
+extern int tree_expr_unsigned_p PARAMS ((tree));
extern int index_type_equal PARAMS ((tree, tree));
extern tree get_inner_array_type PARAMS ((tree));
diff -rup orig/egcs-CVS20000405/gcc/c-typeck.c egcs-CVS20000405/gcc/c-typeck.c
--- orig/egcs-CVS20000405/gcc/c-typeck.c Thu Mar 30 00:02:38 2000
+++ egcs-CVS20000405/gcc/c-typeck.c Thu Apr 6 09:11:24 2000
@@ -2416,11 +2416,12 @@ build_binary_op (code, orig_op0, orig_op
else
sop = xop1, uop = xop0;
- /* 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. */
- if (TREE_CODE (sop) == INTEGER_CST
- && tree_int_cst_sgn (sop) >= 0)
+ /* Do not warn if the signed quantity is an
+ unsuffixed integer literal (or some static
+ constant expression involving such literals or a
+ conditional expression involving such literals)
+ and it is non-negative. */
+ if (tree_expr_unsigned_p (sop))
/* OK */;
/* Do not warn if the comparison is an equality operation,
the unsigned quantity is an integral constant, and it
diff -rup orig/egcs-CVS20000405/gcc/cp/typeck.c egcs-CVS20000405/gcc/cp/typeck.c
--- orig/egcs-CVS20000405/gcc/cp/typeck.c Sun Mar 26 23:23:35 2000
+++ egcs-CVS20000405/gcc/cp/typeck.c Thu Apr 6 09:13:20 2000
@@ -3960,11 +3960,10 @@ build_binary_op (code, orig_op0, orig_op
/* OK */;
/* Do not warn if the signed quantity is an unsuffixed
integer literal (or some static constant expression
+ involving such literals or a conditional expression
involving such literals) and it is non-negative. */
- else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST
- && tree_int_cst_sgn (orig_op0) >= 0)
- || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
- && tree_int_cst_sgn (orig_op1) >= 0))
+ else if ((op0_signed && tree_expr_unsigned_p (orig_op0))
+ || (op1_signed && tree_expr_unsigned_p (orig_op1)))
/* OK */;
/* Do not warn if the comparison is an equality operation,
the unsigned quantity is an integral constant and it does