This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] gcc.dg/compare1.c: Add -fno-short-enums.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 3 Jul 2005 08:18:33 -0700
- Subject: [patch] gcc.dg/compare1.c: Add -fno-short-enums.
Hi,
Attached is a patch to add -fno-short-enums.
Consider
int i(enum mm2 x)
{
return x == (tf?DI2:-1); /* { dg-warning "signed and unsigned" "case 4" } */
}
The rhs of == is of type int because of -1. Now, 'x' is of type mm2
and promoted to int. Since int covers the entire range of mm2,
c-typeck.c:build_binary_op decides not to issue a "comparison between
signed and unsigned" warning. The following "if" statement is
responsible for this decision:
Do not warn if the comparison is being done in a signed type,
since the signed type will only be chosen if it can represent
all the values of the unsigned type. */
if (!TYPE_UNSIGNED (result_type))
/* OK */;
The patch solves the problem as suggested by Paul Brook. (Thanks
Paul!) Specifically, if we add -fno-short-enums, we can force targets
like arm*-*-eabi* and arm*-*-symbianelf* as well as other targets to
use enum of the same size as int. This way, even if somebody adds a
port with short enum, we won't have to touch this testcase.
Tested on x86_64-pc-linux-gnu and arm-none-eabi. OK to apply?
Kazu Hirata
2005-07-03 Kazu Hirata <kazu@codesourcery.com>
* gcc.dg/compare1.c: Add -fno-short-enums.
Index: testsuite/gcc.dg/compare1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/compare1.c,v
retrieving revision 1.3
diff -u -d -p -r1.3 compare1.c
--- testsuite/gcc.dg/compare1.c 5 Jan 2000 19:26:23 -0000 1.3
+++ testsuite/gcc.dg/compare1.c 2 Jul 2005 22:21:44 -0000
@@ -2,7 +2,7 @@
This was inspired by code in gcc. */
/* { dg-do compile } */
-/* { dg-options "-Wsign-compare" } */
+/* { dg-options "-fno-short-enums -Wsign-compare" } */
int tf = 1;