diff mbox series

[Ada] Fix PR ada/98230

Message ID 66994464.DLPFXeAB4U@fomalhaut
State New
Headers show
Series [Ada] Fix PR ada/98230 | expand

Commit Message

Eric Botcazou Dec. 10, 2020, 9:32 p.m. UTC
It's a rather curious malfunction of the 'Mod attribute applied to the 
variable of a loop whose upper bound is dynamic.

Tested on x86-64/Linux, applied on all active branches.


2020-12-10  Ed Schonberg  <schonberg@adacore.com>

	PR ada/98230
	* exp_attr.adb (Expand_N_Attribute_Reference, case Mod): Use base
	type of argument to obtain static bound and required size.


2020-12-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/modular6.adb: New test.
diff mbox series

Patch

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 251fa1449c4..b21592c78b2 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -4702,13 +4702,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