public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-525] [Ada] Spurious error on subprogram with class-wide preconditions
@ 2022-05-17 8:27 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-17 8:27 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c30e5ab027a59a2ffcf7fb2d093ce2b64de712eb
commit r13-525-gc30e5ab027a59a2ffcf7fb2d093ce2b64de712eb
Author: Javier Miranda <miranda@adacore.com>
Date: Fri Mar 18 19:28:52 2022 +0000
[Ada] Spurious error on subprogram with class-wide preconditions
gcc/ada/
* freeze.adb (Build_DTW_Spec): Do not inherit the not-overriding
indicator because the DTW wrapper overrides its wrapped
subprogram.
* contracts.ads (Make_Class_Precondition_Subps): Adding
documentation.
Diff:
---
gcc/ada/contracts.ads | 33 +++++++++++++++++++++++++++++++++
gcc/ada/freeze.adb | 7 +++++++
2 files changed, 40 insertions(+)
diff --git a/gcc/ada/contracts.ads b/gcc/ada/contracts.ads
index adbb0e6eb67..5178373bff3 100644
--- a/gcc/ada/contracts.ads
+++ b/gcc/ada/contracts.ads
@@ -226,6 +226,39 @@ package Contracts is
-- overrides an inherited class-wide precondition (see AI12-0195-1).
-- Late_Overriding enables special handling required for late-overriding
-- subprograms.
+ --
+ -- For example, if we have a subprogram with the following profile:
+ --
+ -- procedure Prim (Obj : TagTyp; <additional formals>)
+ -- with Pre'Class => F1 (Obj) and F2(Obj)
+ --
+ -- We build the following helper that evaluates statically the class-wide
+ -- precondition:
+ --
+ -- function PrimSP (Obj : TagTyp) return Boolean is
+ -- begin
+ -- return F1 (Obj) and F2(Obj);
+ -- end PrimSP;
+ --
+ -- ... and the following helper that evaluates dynamically the class-wide
+ -- precondition:
+ --
+ -- function PrimDP (Obj : TagTyp'Class; ...) return Boolean is
+ -- begin
+ -- return F1 (Obj) and F2(Obj);
+ -- end PrimSP;
+ --
+ -- ... and the following indirect-call wrapper (ICW) that is used by the
+ -- code generated by the compiler for indirect calls:
+ --
+ -- procedure PrimICW (Obj : TagTyp; <additional formals> is
+ -- begin
+ -- if not PrimSP (Obj) then
+ -- $raise_assert_failure ("failed precondition in call at ...");
+ -- end if;
+ --
+ -- Prim (Obj, ...);
+ -- end Prim;
procedure Merge_Class_Conditions (Spec_Id : Entity_Id);
-- Merge and preanalyze all class-wide conditions of Spec_Id (class-wide
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 7d90f512245..ca0ffe39c25 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -1619,6 +1619,13 @@ package body Freeze is
DTW_Spec := Build_Overriding_Spec (Par_Prim, R);
DTW_Id := Defining_Entity (DTW_Spec);
+ -- Clear the not-overriding indicator since the DTW wrapper overrides
+ -- its wrapped subprogram; required because if present in the parent
+ -- primitive, given that Build_Overriding_Spec inherits it, we report
+ -- spurious errors.
+
+ Set_Must_Not_Override (DTW_Spec, False);
+
-- Add minimal decoration of fields
Mutate_Ekind (DTW_Id, Ekind (Par_Prim));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-17 8:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 8:27 [gcc r13-525] [Ada] Spurious error on subprogram with class-wide preconditions 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).