This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Skip part of gcc.dg/compare1.c on some ARM ports.


Hi,

Attached is a patch to skip part of gcc.dg/compare1.c on some ARM ports.

The last test in gcc.dg/compare1.c does not apply to those ARM ports
with short enums.

I am not a language laywer, so don't beat me too hard if the following
analysis is bogus. :-)

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 */;

Since we cannot skip a single test, the patch splits the last test to
a separate file compare9.c, which is skipped if we have short enums.
According to config/arm/arm.h and config.gcc, those ports with short
enums are exactly arm*-*-eabi* arm*-*-symbianelf*.

Tested on arm-none-eabi and x86_64-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-06-25  Kazu Hirata  <kazu@codesourcery.com>

	* gcc.dg/compare1.c: Move the last test to ...
	* gcc.dg/compare9.c: ... here.

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	25 Jun 2005 14:18:17 -0000
@@ -32,9 +32,4 @@ int h(enum mm2 x)
 {
   return x == (tf?DI2:SI2); /* { dg-bogus "signed and unsigned" "case 3" } */
 }
-
-int i(enum mm2 x)
-{
-  return x == (tf?DI2:-1); /* { dg-warning "signed and unsigned" "case 4" } */
-}
--- /dev/null	2004-06-24 11:05:26.000000000 -0700
+++ testsuite/gcc.dg/compare9.c	2005-06-24 23:18:56.000000000 -0700
@@ -0,0 +1,22 @@
+/* Test for a warning on comparison between signed and unsigned.
+   This was split off of compare1.c to accomodate ARM's short enums.  */
+
+/* { dg-do compile } */
+/* On these two ARM ports, enums are smaller than int.  Since such a
+   enum is promoted to int, which can contain the entire range of the
+   enum, we do not need to issue a warning.  */
+/* { dg-skip-if "" { "arm*-*-eabi*" "arm*-*-symbianelf*" } { "*" } { "" } } */
+/* { dg-options "-Wsign-compare" } */
+
+int tf = 1;
+
+/* This enumeration fits entirely in a signed int, but is unsigned anyway.  */
+enum mm2
+{
+  VOID2, SI2, DI2, MAX2
+};
+
+int i(enum mm2 x)
+{
+  return x == (tf?DI2:-1); /* { dg-warning "signed and unsigned" "case 1" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]