]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/15549 (true !< 'a')
authorJosef Zlomek <zlomekj@suse.cz>
Mon, 28 Jun 2004 08:03:47 +0000 (10:03 +0200)
committerJosef Zlomek <zlomek@gcc.gnu.org>
Mon, 28 Jun 2004 08:03:47 +0000 (08:03 +0000)
PR c/15549
Backport from mainline
2003-08-19  Mark Mitchell  <mark@codesourcery.com>

PR c++/11946
* convert.c (convert_to_integer): Use CONVERT_EXPR (instead of
NOP_EXPR) when necessary.

PR c/15549
Backport from mainline
2003-08-19  Mark Mitchell  <mark@codesourcery.com>

PR c++/11946.C
* gcc.dg/c99-bool-1.c: Remove bogus warning.

From-SVN: r83765

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-bool-1.c

index 2c801706698f249abb44a1a2bf5afc4ffc0d1bcb..d6a49f1543c16c1e3ff3499bb1d2e3a12a1487e0 100644 (file)
@@ -1,3 +1,13 @@
+2004-06-28  Josef Zlomek  <zlomekj@suse.cz>
+
+       PR c/15549
+       Backport from mainline
+       2003-08-19  Mark Mitchell  <mark@codesourcery.com>
+
+               PR c++/11946
+               * convert.c (convert_to_integer): Use CONVERT_EXPR (instead of
+               NOP_EXPR) when necessary.
+
 2004-06-17  Ian Lance Taylor  <ian@wasabisystems.com>
 
        PR middle-end/16038
index e440e35f57577a9f0bedbf1b124f9f8a1aabbd97..aa0d0fb414061a2879f83115d97102bc5a0714e1 100644 (file)
@@ -182,7 +182,27 @@ convert_to_integer (type, expr)
         we are truncating EXPR.  */
 
       else if (outprec >= inprec)
-       return build1 (NOP_EXPR, type, expr);
+       {
+         enum tree_code code;
+
+         /* If the precision of the EXPR's type is K bits and the
+            destination mode has more bits, and the sign is changing,
+            it is not safe to use a NOP_EXPR.  For example, suppose
+            that EXPR's type is a 3-bit unsigned integer type, the
+            TYPE is a 3-bit signed integer type, and the machine mode
+            for the types is 8-bit QImode.  In that case, the
+            conversion necessitates an explicit sign-extension.  In
+            the signed-to-unsigned case the high-order bits have to
+            be cleared.  */
+         if (TREE_UNSIGNED (type) != TREE_UNSIGNED (TREE_TYPE (expr))
+             && (TYPE_PRECISION (TREE_TYPE (expr))
+                 != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)))))
+           code = CONVERT_EXPR;
+         else
+           code = NOP_EXPR;
+
+         return build1 (code, type, expr);
+       }
 
       /* If TYPE is an enumeral type or a type with a precision less
         than the number of bits in its mode, do the conversion to the
index 051e1ff2d07ba276ccbb3fe5a0618eab540d645a..da385606296a11272b3ea704e0444fe6d4a72735 100644 (file)
@@ -1,3 +1,12 @@
+2004-06-28  Josef Zlomek  <zlomekj@suse.cz>
+
+       PR c/15549
+       Backport from mainline
+       2003-08-19  Mark Mitchell  <mark@codesourcery.com>
+
+               PR c++/11946.C
+               * gcc.dg/c99-bool-1.c: Remove bogus warning.
+
 2004-05-31  Release Manager
 
        * GCC 3.3.4 Released.
index 1037eb55173a8d843e19817aa99336375c0da55c..710219620b7e334b86ef12980be9fe13b14cbdd5 100644 (file)
@@ -228,9 +228,7 @@ main (void)
     abort ();
   if ((u |= 2) != 1)
     abort ();
-  /* ??? A bit queer, since this gets optimized to ((u = (u != 3)) != 1)
-     early in semantic analysis, which then yields the warning below.  */
-  if ((u ^= 3) != 1)   /* { dg-warning "always true due to limited range" } */
+  if ((u ^= 3) != 1)
     abort ();
   /* Test comma expressions.  */
   u = 1;