public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Claire Dross <dross@adacore.com>
Subject: [Ada] Support chained calls to traversal functions in SPARK
Date: Tue, 17 Sep 2019 08:07:00 -0000	[thread overview]
Message-ID: <20190917080633.GA37536@adacore.com> (raw)

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

This change only affects the SPARK toolset. In the part of semantic
analysis enforcing ownership rules for SPARK, it corrects a crash in
analysis of a declaration of a local borrower whose definition is a
chain of several calls to traversal functions.

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

2019-09-17  Claire Dross  <dross@adacore.com>

gcc/ada/

	* sem_spark.adb (Get_Observed_Or_Borrowed_Expr): If the
	definition of a local borrower contains calls to traversal
	functions, the borrowed expression is the first parameter of the
	first traversal function call in the definition.

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

--- gcc/ada/sem_spark.adb
+++ gcc/ada/sem_spark.adb
@@ -708,8 +708,8 @@ package body Sem_SPARK is
    function Get_Observed_Or_Borrowed_Expr (Expr : Node_Id) return Node_Id;
    pragma Precondition (Is_Path_Expression (Expr));
    --  Return the expression being borrowed/observed when borrowing or
-   --  observing Expr. If Expr is a call to a traversal function, this is
-   --  the first actual, otherwise it is Expr.
+   --  observing Expr. If Expr contains a call to traversal function, this is
+   --  the first actual of the first such call, otherwise it is Expr.
 
    function Get_Perm (N : Node_Or_Entity_Id) return Perm_Kind;
    --  The function that takes a name as input and returns a permission
@@ -3772,12 +3772,61 @@ package body Sem_SPARK is
    -----------------------------------
 
    function Get_Observed_Or_Borrowed_Expr (Expr : Node_Id) return Node_Id is
+
+      function Find_Func_Call (Expr : Node_Id) return Node_Id;
+      --  Search for function calls in the prefixes of Expr
+
+      --------------------
+      -- Find_Func_Call --
+      --------------------
+
+      function Find_Func_Call (Expr : Node_Id) return Node_Id is
+      begin
+         case Nkind (Expr) is
+            when N_Expanded_Name
+               | N_Identifier
+            =>
+               return Empty;
+
+            when N_Explicit_Dereference
+               | N_Indexed_Component
+               | N_Selected_Component
+               | N_Slice
+            =>
+               return Find_Func_Call (Prefix (Expr));
+
+            when N_Qualified_Expression
+               | N_Type_Conversion
+               | N_Unchecked_Type_Conversion
+            =>
+               return Find_Func_Call (Expression (Expr));
+
+            when N_Function_Call =>
+               return Expr;
+
+            when others =>
+               raise Program_Error;
+         end case;
+      end Find_Func_Call;
+
+      B_Expr : Node_Id := Expr;
+
    begin
-      if Is_Traversal_Function_Call (Expr) then
-         return First_Actual (Expr);
-      else
-         return Expr;
-      end if;
+      --  Search for the first call to a traversal function in Expr. If there
+      --  is one, its first parameter is the borrowed expression. Otherwise,
+      --  it is Expr.
+
+      loop
+         declare
+            Call : constant Node_Id := Find_Func_Call (B_Expr);
+         begin
+            exit when No (Call);
+            pragma Assert (Is_Traversal_Function_Call (Call));
+            B_Expr := First_Actual (Call);
+         end;
+      end loop;
+
+      return B_Expr;
    end Get_Observed_Or_Borrowed_Expr;
 
    --------------


                 reply	other threads:[~2019-09-17  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190917080633.GA37536@adacore.com \
    --to=derodat@adacore.com \
    --cc=dross@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).