diff mbox

[Ada] Spurious dimensionality errors in inlined bodies.

Message ID 20170119113343.GA34938@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 19, 2017, 11:33 a.m. UTC
This patch removes spurious dimensionality errors in programs that are compiled
with front-end inlining (as in SPARK mode). The original model of dimensionality
checking analyzes only nodes coming from source because the correctness of the
dimensioned program only depends on source user code. However, when inlining is
enabled, expressions can include both source references and references to
internal entities created for the formals of a subprogram in an inlined call.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-01-19  Ed Schonberg  <schonberg@adacore.com>

	* sem_dim.adb (Analyze_Dimension): Analyze object declaration and
	identifier nodes that do not come from source, to handle properly
	dimensionality check within an inlined body which inclddes both
	original operands and rewritten operands. This removes spurious
	dimensionality errors in the presence of front-end inlining,
	as well as in SPARK mode.
diff mbox

Patch

Index: sem_dim.adb
===================================================================
--- sem_dim.adb	(revision 244612)
+++ sem_dim.adb	(working copy)
@@ -1122,16 +1122,22 @@ 
       --  Aspect is an Ada 2012 feature. Note that there is no need to check
       --  dimensions for nodes that don't come from source, except for subtype
       --  declarations where the dimensions are inherited from the base type,
-      --  and for explicit dereferences generated when expanding iterators.
+      --  for explicit dereferences generated when expanding iterators, and
+      --  for object declarations generated for inlining.
 
       if Ada_Version < Ada_2012 then
          return;
 
-      elsif not Comes_From_Source (N)
-        and then Nkind (N) /= N_Subtype_Declaration
-        and then Nkind (N) /= N_Explicit_Dereference
-      then
-         return;
+      elsif not Comes_From_Source (N) then
+         if Nkind_In (N, N_Explicit_Dereference,
+                         N_Identifier,
+                         N_Object_Declaration,
+                         N_Subtype_Declaration)
+         then
+            null;
+         else
+            return;
+         end if;
       end if;
 
       case Nkind (N) is
@@ -2138,7 +2144,8 @@ 
             end if;
          end if;
 
-         --  Removal of dimensions in expression
+         --  Remove dimensions in expression after checking consistency
+         --  with given type.
 
          Remove_Dimensions (Expr);
       end if;