public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5665] ada: Fix miscompilation of loop over boolean range
@ 2023-11-21 10:00 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2023-11-21 10:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4649c079409ec6cb67cd2cca0df81877e53c78b4

commit r14-5665-g4649c079409ec6cb67cd2cca0df81877e53c78b4
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Wed Oct 25 17:52:38 2023 +0200

    ada: Fix miscompilation of loop over boolean range
    
    The optimized form generated in this case turns out to be problematic.
    
    gcc/ada/
    
            * gcc-interface/trans.cc (Loop_Statement_to_gnu): Always use the
            simpler form for a loop with a boolean iteration variable.

Diff:
---
 gcc/ada/gcc-interface/trans.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index c7d91628f80..9c418beda96 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -3021,7 +3021,9 @@ Loop_Statement_to_gnu (Node_Id gnat_node)
 	}
 
       /* We use two different strategies to translate the loop, depending on
-	 whether optimization is enabled.
+	 whether optimization is enabled, except for the very peculiar case
+	 of a loop running over a boolean type where we use the simpler form
+	 in order to avoid manipulating negative values in a boolean context.
 
 	 If it is, we generate the canonical loop form expected by the loop
 	 optimizer and the loop vectorizer, which is the do-while form:
@@ -3067,7 +3069,9 @@ Loop_Statement_to_gnu (Node_Id gnat_node)
 
 	 which works in all cases.  */
 
-      if (optimize && !optimize_debug)
+      if (optimize
+	  && !optimize_debug
+	  && TREE_CODE (gnu_base_type) != BOOLEAN_TYPE)
 	{
 	  /* We can use the do-while form directly if GNU_FIRST-1 doesn't
 	     overflow.  */

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

only message in thread, other threads:[~2023-11-21 10:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 10:00 [gcc r14-5665] ada: Fix miscompilation of loop over boolean range Marc Poulhi?s

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).