From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED] ada: Fix exception raised on invalid contract in generic package
Date: Tue, 13 Jun 2023 09:38:23 +0200 [thread overview]
Message-ID: <20230613073823.240135-1-poulhies@adacore.com> (raw)
From: Eric Botcazou <ebotcazou@adacore.com>
This lets the compiler give a proper error message instead.
gcc/ada/
* contracts.adb (Contract_Error): New exception.
(Add_Contract_Item): Raise Contract_Error instead of Program_Error.
(Add_Generic_Contract_Pragma): Deal with Contract_Error.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/contracts.adb | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index ae9e07ffc16..19073d1e4d8 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -62,6 +62,11 @@ with Warnsw; use Warnsw;
package body Contracts is
+ Contract_Error : exception;
+ -- This exception is raised by Add_Contract_Item when it is invoked on an
+ -- invalid pragma. Note that clients of the package must filter them out
+ -- before invoking Add_Contract_Item, so it should not escape the package.
+
procedure Analyze_Package_Instantiation_Contract (Inst_Id : Entity_Id);
-- Analyze all delayed pragmas chained on the contract of package
-- instantiation Inst_Id as if they appear at the end of a declarative
@@ -198,7 +203,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Entry bodies, the applicable pragmas are:
@@ -216,7 +221,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Entry or subprogram declarations, the applicable pragmas are:
@@ -268,7 +273,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Packages or instantiations, the applicable pragmas are:
@@ -292,7 +297,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Package bodies, the applicable pragmas are:
@@ -305,7 +310,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- The four volatility refinement pragmas are ok for all types.
@@ -343,7 +348,7 @@ package body Contracts is
-- The pragma is not a proper contract item
- raise Program_Error;
+ raise Contract_Error;
end if;
end;
@@ -367,7 +372,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Task bodies, the applicable pragmas are:
@@ -381,7 +386,7 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
-- Task units, the applicable pragmas are:
@@ -416,11 +421,11 @@ package body Contracts is
-- The pragma is not a proper contract item
else
- raise Program_Error;
+ raise Contract_Error;
end if;
else
- raise Program_Error;
+ raise Contract_Error;
end if;
end Add_Contract_Item;
@@ -2225,6 +2230,12 @@ package body Contracts is
else
Add_Contract_Item (Prag, Templ_Id);
end if;
+
+ exception
+ -- We do not stop the compilation at this point in the case of an
+ -- invalid pragma because it will be properly diagnosed afterward.
+
+ when Contract_Error => null;
end Add_Generic_Contract_Pragma;
-- Local variables
--
2.40.0
reply other threads:[~2023-06-13 7:38 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=20230613073823.240135-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=ebotcazou@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).