Debian Codegraph @

gcc/testsuite/gnat.dg/sync_tag_finalize.adb

raw
1 -- In previous versions of GNAT there was a curious bug that caused
2 -- compilation to fail in the case of a synchronized private extension
3 -- with non-default discriminants, where the creation of a constrained object
4 -- (and thus subtype) caused the TSS deep finalize machinery of the internal
5 -- class-wide constratined subtype (TConstrainedC) to construct a malformed
6 -- TSS finalize address body. The issue was that the machinery climbs
7 -- the type parent chain looking for a "non-constrained" type to use as a
8 -- designated (class-wide) type for a dispatching call to a higher TSS DF
9 -- subprogram. When there is a discriminated synchronized private extension
10 -- with known, non-default discriminants (thus unconstrained/indefinite),
11 -- that search ends up at that private extension declaration. Since the
12 -- underlying type is actually a concurrent type, class-wide TSS finalizers
13 -- are not built for the type, but rather the corresponding record type. The
14 -- TSS machinery that selects the designated type was prevsiously unaware of
15 -- this caveat, and thus selected an incompatible designated type, leading to
16 -- failed compilation.
17 --
18 -- TL;DR: When creating a constrained subtype of a synchronized private
19 -- extension with known non-defaulted disciminants, the class-wide TSS
20 -- address finalization body for the constrained subtype should dispatch to
21 -- the corresponding record (class-wide) type deep finalize subprogram.
22
23 -- { dg-do compile }
24
25 procedure Sync_Tag_Finalize is
26
27 package Ifaces is
28
29 type Test_Interface is synchronized interface;
30
31 procedure Interface_Action (Test: in out Test_Interface) is abstract;
32
33 end Ifaces;
34
35
36 package Implementation is
37 type Test_Implementation
38 (Constraint: Positive) is
39 synchronized new Ifaces.Test_Interface with private;
40
41 private
42 protected type Test_Implementation
43 (Constraint: Positive)
44 is new Ifaces.Test_Interface with
45
46 overriding procedure Interface_Action;
47
48 end Test_Implementation;
49 end Implementation;
50
51 package body Implementation is
52 protected body Test_Implementation is
53 procedure Interface_Action is null;
54 end;
55 end Implementation;
56
57 Constrained: Implementation.Test_Implementation(2);
58 begin
59 null;
60 end;