aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2020-12-10 22:26:57 +0100
committerEric Botcazou <ebotcazou@adacore.com>2020-12-10 22:32:05 +0100
commit87c40733898283f0d1e48bcbf8055c2718064e77 (patch)
tree3c88b4760154d372b905cb8270f0bd02ca9ea31e /gcc
parent92cad21017f981a3f9f73934ca18d5f76a492421 (diff)
downloadgcc-87c40733898283f0d1e48bcbf8055c2718064e77.zip
gcc-87c40733898283f0d1e48bcbf8055c2718064e77.tar.gz
gcc-87c40733898283f0d1e48bcbf8055c2718064e77.tar.bz2
Fix PR ada/98230
It's a rather curious malfunction of the 'Mod attribute applied to the variable of a loop whose upper bound is dynamic. gcc/ada/ChangeLog: PR ada/98230 * exp_attr.adb (Expand_N_Attribute_Reference, case Mod): Use base type of argument to obtain static bound and required size. gcc/testsuite/ChangeLog: * gnat.dg/modular6.adb: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_attr.adb6
-rw-r--r--gcc/testsuite/gnat.dg/modular6.adb15
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 36e1815..c44285c 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -4447,13 +4447,15 @@ package body Exp_Attr is
when Attribute_Mod => Mod_Case : declare
Arg : constant Node_Id := Relocate_Node (First (Exprs));
- Hi : constant Node_Id := Type_High_Bound (Etype (Arg));
+ Hi : constant Node_Id := Type_High_Bound (Base_Type (Etype (Arg)));
Modv : constant Uint := Modulus (Btyp);
begin
-- This is not so simple. The issue is what type to use for the
- -- computation of the modular value.
+ -- computation of the modular value. In addition we need to use
+ -- the base type as above to retrieve a static bound for the
+ -- comparisons that follow.
-- The easy case is when the modulus value is within the bounds
-- of the signed integer type of the argument. In this case we can
diff --git a/gcc/testsuite/gnat.dg/modular6.adb b/gcc/testsuite/gnat.dg/modular6.adb
new file mode 100644
index 0000000..f0f1c80
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/modular6.adb
@@ -0,0 +1,15 @@
+-- { dg-do compile }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Modular6 is
+ Max : Integer := 0;
+
+ type Modulus is mod 3;
+begin
+ Max := 30;
+
+ for N in 1 .. Max loop
+ Put_Line("N: " & Integer'Image(N) & " Modulus: " & Integer'Image(Modulus'Modulus) & " Mod:" & Modulus'Image(Modulus'Mod(N)));
+ end loop;
+end;