This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for bug 22311
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 1 Aug 2005 01:34:40 +0000 (UTC)
- Subject: Patch for bug 22311
This patch fixes bug 22311, a 4.0/4.1 regression with -fshort-enums
relating to use of c_common_type where the common_type wrapper is
needed. The fix used here is the simple local fix of using the
common_type wrapper. Longer term the front end ought to stop doing
these optimizations (shortening types) when building up trees, leaving
it to language-independent optimizations (whether fold or some other
pass) to remove unnecessary conversions, so maybe eventually removing
the need for this wrapper and ensuring c_common_type really does only
receive properly promoted types.
Bootstrapped with no regressions on x86_64-unknown-linux-gnu, mainline
and 4.0 branch. Applied to mainline and 4.0 branch.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2005-08-01 Joseph S. Myers <joseph@codesourcery.com>
PR c/22311
* c-typeck.c (build_binary_op): Use common_type wrapper on
shortened types.
(common_type): Update comment.
testsuite:
2005-08-01 Joseph S. Myers <joseph@codesourcery.com>
PR c/22311
* gcc.dg/pr22311-1.c : New test.
diff -rupN GCC.orig/gcc/c-typeck.c GCC/gcc/c-typeck.c
--- GCC.orig/gcc/c-typeck.c 2005-07-29 02:43:23.000000000 +0000
+++ GCC/gcc/c-typeck.c 2005-07-31 22:59:26.000000000 +0000
@@ -637,7 +637,8 @@ c_common_type (tree t1, tree t2)
return t2;
}
-/* Wrapper around c_common_type that is used by c-common.c. ENUMERAL_TYPEs
+/* Wrapper around c_common_type that is used by c-common.c and other
+ front end optimizations that remove promotions. ENUMERAL_TYPEs
are allowed here and are converted to their compatible integer types.
BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
preferably a non-Boolean type as the common type. */
@@ -7948,7 +7949,7 @@ build_binary_op (enum tree_code code, tr
&& (unsigned0 || !uns))
result_type
= c_common_signed_or_unsigned_type
- (unsigned0, c_common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
+ (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
else if (TREE_CODE (arg0) == INTEGER_CST
&& (unsigned1 || !uns)
&& (TYPE_PRECISION (TREE_TYPE (arg1))
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pr22311-1.c GCC/gcc/testsuite/gcc.dg/pr22311-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/pr22311-1.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pr22311-1.c 2005-07-31 22:54:40.000000000 +0000
@@ -0,0 +1,6 @@
+/* Bug 22311: ICE with -fshort-enums on shortened operations. */
+/* { dg-do compile } */
+/* { dg-options "-fshort-enums" } */
+
+typedef enum { A = 1 } E;
+void f(E e, unsigned char c) { c |= e; }