public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2078] [Ada] Warn on statically known empty loop caused by constraint
@ 2021-07-06 14:50 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-06 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8ff47b3f88330ae222d393883d6b4a9c5393dc69

commit r12-2078-g8ff47b3f88330ae222d393883d6b4a9c5393dc69
Author: Ghjuvan Lacambre <lacambre@adacore.com>
Date:   Wed May 12 14:43:06 2021 +0200

    [Ada] Warn on statically known empty loop caused by constraint
    
    gcc/ada/
    
            * sem_ch5.adb (Analyze_Loop_Parameter_Specification): Check for
            empty loops caused by constraints.

Diff:
---
 gcc/ada/sem_ch5.adb | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 3c98d738297..ccd5a3728c7 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -3377,6 +3377,32 @@ package body Sem_Ch5 is
                        ("\loop executes zero times or raises "
                         & "Constraint_Error??", Bad_Bound);
                   end if;
+
+                  if Compile_Time_Compare (LLo, LHi, Assume_Valid => False)
+                    = GT
+                  then
+                     Error_Msg_N ("??constrained range is null",
+                       Constraint (DS));
+
+                     --  Additional constraints on modular types can be
+                     --  confusing, add more information.
+
+                     if Ekind (Etype (DS)) = E_Modular_Integer_Subtype then
+                        Error_Msg_Uint_1 := Intval (LLo);
+                        Error_Msg_Uint_2 := Intval (LHi);
+                        Error_Msg_NE ("\iterator has modular type &, " &
+                          "so the loop has bounds ^ ..^",
+                          Constraint (DS),
+                          Subtype_Mark (DS));
+                     end if;
+
+                     Set_Is_Null_Loop (Loop_Nod);
+                     Null_Range := True;
+
+                     --  Suppress other warnigns about the body of the loop, as
+                     --  it will never execute.
+                     Set_Suppress_Loop_Warnings (Loop_Nod);
+                  end if;
                end;
             end if;


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

only message in thread, other threads:[~2021-07-06 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 14:50 [gcc r12-2078] [Ada] Warn on statically known empty loop caused by constraint Pierre-Marie de Rodat

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