public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2298] Fix PR 110487: invalid signed boolean value
@ 2023-07-04 17:20 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-07-04 17:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2e5c1b123d5bc4b7eca91f1eb2dab88d0bcdfcfa

commit r14-2298-g2e5c1b123d5bc4b7eca91f1eb2dab88d0bcdfcfa
Author: Andrew Pinski <apinski@marvell.com>
Date:   Fri Jun 30 17:50:08 2023 -0700

    Fix PR 110487: invalid signed boolean value
    
    This fixes the first part of this bug where `a ? -1 : 0`
    would cause a value of 1 into the signed boolean value.
    It fixes the problem by casting to an integer type of
    the same size/signedness before doing the negative and
    then casting to the type of expression.
    
    OK? Bootstrapped and tested on x86_64.
    
    gcc/ChangeLog:
    
            * match.pd (a?-1:0): Cast type an integer type
            rather the type before the negative.
            (a?0:-1): Likewise.

Diff:
---
 gcc/match.pd | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 861b7dfcddd..637d22ccefd 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4705,7 +4705,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     /* a ? -1 : 0 -> -a.  No need to check the TYPE_PRECISION not being 1
        here as the powerof2cst case above will handle that case correctly.  */
     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
-     (negate (convert (convert:boolean_type_node @0))))))
+     (with {
+       auto prec = TYPE_PRECISION (type);
+       auto unsign = TYPE_UNSIGNED (type);
+       tree inttype = build_nonstandard_integer_type (prec, unsign);
+      }
+      (convert (negate (convert:inttype (convert:boolean_type_node @0))))))))
   (if (integer_zerop (@1))
    (with {
       tree booltrue = constant_boolean_node (true, boolean_type_node);
@@ -4724,7 +4729,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
        here as the powerof2cst case above will handle that case correctly.  */
      (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
-      (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))))
+      (with {
+	auto prec = TYPE_PRECISION (type);
+	auto unsign = TYPE_UNSIGNED (type);
+	tree inttype = build_nonstandard_integer_type (prec, unsign);
+       }
+       (convert
+	(negate
+         (convert:inttype
+	  (bit_xor (convert:boolean_type_node @0) { booltrue; } )
+	 )
+	)
+       )
+      )
+     )
     )
    )
   )

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-04 17:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 17:20 [gcc r14-2298] Fix PR 110487: invalid signed boolean value Andrew Pinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).