From ead51d365447a3441fa087e0f9120b8199d19da2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 4 Nov 2008 21:51:38 +0100 Subject: [PATCH] re PR c/35430 (ICE with complex arithmetic) PR c/35430 * c-common.c (warn_for_sign_compare): For complex result_type use component's type. * gcc.dg/pr35430.c: New test. * g++.dg/warn/Wsign-compare-2.C: New test. Co-Authored-By: Andrew Pinski From-SVN: r141587 --- gcc/ChangeLog | 7 +++++++ gcc/c-common.c | 12 +++++++----- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/warn/Wsign-compare-2.C | 10 ++++++++++ gcc/testsuite/gcc.dg/pr35430.c | 10 ++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-compare-2.C create mode 100644 gcc/testsuite/gcc.dg/pr35430.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a0152b15699..7e062db5b96 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-11-04 Jakub Jelinek + Andrew Pinski + + PR c/35430 + * c-common.c (warn_for_sign_compare): For complex result_type + use component's type. + 2008-11-04 Jakub Jelinek * print-tree.c (print_node): Use code instead of TREE_CODE (node). diff --git a/gcc/c-common.c b/gcc/c-common.c index 3a97bd7aaf5..ea7379edc5c 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -8241,7 +8241,7 @@ warn_for_sign_compare (location_t location, && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0)) - != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1))) + != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1))) { warning_at (location, OPT_Wsign_compare, "comparison between types %qT and %qT", @@ -8258,9 +8258,9 @@ warn_for_sign_compare (location_t location, /* OK */; else { - tree sop, uop; + tree sop, uop, base_type; bool ovf; - + if (op0_signed) sop = orig_op0, uop = orig_op1; else @@ -8268,6 +8268,8 @@ warn_for_sign_compare (location_t location, STRIP_TYPE_NOPS (sop); STRIP_TYPE_NOPS (uop); + base_type = (TREE_CODE (result_type) == COMPLEX_TYPE + ? TREE_TYPE (result_type) : result_type); /* Do not warn if the signed quantity is an unsuffixed integer literal (or some static constant expression involving such @@ -8280,7 +8282,7 @@ warn_for_sign_compare (location_t location, in the result if the result were signed. */ else if (TREE_CODE (uop) == INTEGER_CST && (resultcode == EQ_EXPR || resultcode == NE_EXPR) - && int_fits_type_p (uop, c_common_signed_type (result_type))) + && int_fits_type_p (uop, c_common_signed_type (base_type))) /* OK */; /* In C, do not warn if the unsigned quantity is an enumeration constant and its maximum value would fit in the result if the @@ -8288,7 +8290,7 @@ warn_for_sign_compare (location_t location, else if (!c_dialect_cxx() && TREE_CODE (uop) == INTEGER_CST && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop)), - c_common_signed_type (result_type))) + c_common_signed_type (base_type))) /* OK */; else warning_at (location, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index daf656f53f2..b2dfc5927d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-11-04 Jakub Jelinek + Andrew Pinski + + PR c/35430 + * gcc.dg/pr35430.c: New test. + * g++.dg/warn/Wsign-compare-2.C: New test. + 2008-11-04 Jakub Jelinek PR c/37106 diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C new file mode 100644 index 00000000000..2b8360648fa --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C @@ -0,0 +1,10 @@ +// PR c/35430 +// { dg-do compile } +// { dg-options "-Wsign-compare" } + +void +foo (__complex__ int i) +{ + i == 0u; + i == ~1u; // { dg-warning "comparison between signed and unsigned integer expressions" } +} diff --git a/gcc/testsuite/gcc.dg/pr35430.c b/gcc/testsuite/gcc.dg/pr35430.c new file mode 100644 index 00000000000..ab5e4cac8a5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35430.c @@ -0,0 +1,10 @@ +/* PR c/35430 */ +/* { dg-do compile } */ +/* { dg-options "-Wsign-compare" } */ + +void +foo (__complex__ int i) +{ + i == 0u; + i == ~1u; /* { dg-warning "comparison between signed and unsigned integer expressions" } */ +} -- 2.30.2