public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix handling of generic actuals with default expression in SPARK
@ 2018-11-14 11:43 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2018-11-14 11:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 911 bytes --]

Both in the GNAT frontend and in the GNATprove backend we have
several checks related to generic actuals of mode IN that rely on the
Corresponding_Generic_Association flag. However, this flag was only set
for actuals with explicit expressions from the generic instance and unset
for actuals with implicit expressions from the generic unit.

For example, the code from the added testcase was wrongly rejected with
a message that Y (which is an actual with a default expression) cannot
appear in the Initializes contract. Now this code is accepted.

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

2018-11-14  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_ch12.adb (Instantiate_Object): Set
	Corresponding_Generic_Association on generic actuals with
	default expression.
	* sinfo.ads (Corresponding_Generic_Association): Update comment.

gcc/testsuite/

	* gnat.dg/generic_actuals.adb: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2020 bytes --]

--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -11097,6 +11097,9 @@ package body Sem_Ch12 is
                 Expression             => New_Copy_Tree
                                             (Default_Expression (Formal)));
 
+            Set_Corresponding_Generic_Association
+              (Decl_Node, Expression (Decl_Node));
+
             Append (Decl_Node, List);
             Set_Analyzed (Expression (Decl_Node), False);
 

--- gcc/ada/sinfo.ads
+++ gcc/ada/sinfo.ads
@@ -1106,9 +1106,11 @@ package Sinfo is
    --  Corresponding_Generic_Association (Node5-Sem)
    --    This field is defined for object declarations and object renaming
    --    declarations. It is set for the declarations within an instance that
-   --    map generic formals to their actuals. If set, the field points to
-   --    a generic_association which is the original parent of the expression
-   --    or name appearing in the declaration. This simplifies ASIS queries.
+   --    map generic formals to their actuals. If set, the field points either
+   --    to a copy of a default expression for an actual of mode IN or to a
+   --    generic_association which is the original parent of the expression or
+   --    name appearing in the declaration. This simplifies ASIS and GNATprove
+   --    queries.
 
    --  Corresponding_Integer_Value (Uint4-Sem)
    --    This field is set in real literals of fixed-point types (it is not

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/generic_actuals.adb
@@ -0,0 +1,18 @@
+--  { dg-do compile }
+--  { dg-options "-gnatd.F" }
+
+procedure Generic_Actuals with SPARK_Mode is
+   generic
+      X : Integer;
+      Y : Integer := 0;
+   package Q with Initializes => (XX => X, YY => Y) is
+      --  Both X and Y actuals can appear in the Initializes contract,
+      --  i.e. the default expression of Y should not matter.
+      XX : Integer := X;
+      YY : Integer := Y;
+   end Q;
+
+   package Inst is new Q (X => 0);
+begin
+   null;
+end Generic_Actuals;


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

only message in thread, other threads:[~2018-11-14 11:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 11:43 [Ada] Fix handling of generic actuals with default expression in SPARK 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).