Debian Codegraph @

gcc/testsuite/gnat.dg/strub_intf1.adb

raw
1 -- { dg-do compile }
2 -- { dg-options "-fdump-ipa-strub" }
3 -- { dg-require-effective-target strub }
4
5 -- Check that at-calls dispatching calls to interfaces are transformed.
6
7 procedure Strub_Intf1 is
8 package Foo is
9 type TX is Interface;
10 procedure P (I : Integer; X : TX) is abstract;
11 pragma Machine_Attribute (P, "strub", "at-calls");
12 function F (X : access TX) return Integer is abstract;
13 pragma Machine_Attribute (F, "strub", "at-calls");
14
15 type A is new TX with null record;
16
17 procedure P (I : Integer; X : A);
18 pragma Machine_Attribute (P, "strub", "at-calls");
19
20 function F (X : access A) return Integer;
21 pragma Machine_Attribute (F, "strub", "at-calls");
22
23 type B is new TX with null record;
24
25 overriding
26 procedure P (I : Integer; X : B);
27 pragma Machine_Attribute (P, "strub", "at-calls");
28
29 overriding
30 function F (X : access B) return Integer;
31 pragma Machine_Attribute (F, "strub", "at-calls");
32
33 end Foo;
34
35 package body Foo is
36 procedure P (I : Integer; X : A) is
37 begin
38 null;
39 end;
40
41 function F (X : access A) return Integer is (0);
42
43 overriding
44 procedure P (I : Integer; X : B) is
45 begin
46 null;
47 end;
48
49 overriding
50 function F (X : access B) return Integer is (1);
51
52 end Foo;
53
54 use Foo;
55
56 procedure Q (X : TX'Class) is
57 begin
58 P (-1, X);
59 end;
60
61 XA : aliased A;
62 XB : aliased B;
63 I : Integer := 0;
64 XC : access TX'Class;
65 begin
66 Q (XA);
67 Q (XB);
68
69 I := I + F (XA'Access);
70 I := I + F (XB'Access);
71
72 XC := XA'Access;
73 I := I + F (XC);
74
75 XC := XB'Access;
76 I := I + F (XC);
77 end Strub_Intf1;
78
79 -- { dg-final { scan-ipa-dump-times "\[(\]strub \[(\]at-calls\[)\]\[)\]" 4 "strub" } }
80
81 -- Count the strub-at-calls non-dispatching calls
82 -- (+ 2 each, for the matching prototypes)
83 -- { dg-final { scan-ipa-dump-times "foo\.p \[(\]\[^\n\]*watermark" 2 "strub" } }
84 -- { dg-final { scan-ipa-dump-times "foo\.f \[(\]\[^\n\]*watermark" 4 "strub" } }
85
86 -- Count the strub-at-calls dispatching calls.
87 -- { dg-final { scan-ipa-dump-times "_\[0-9\]* \[(\]\[^\n\]*watermark" 3 "strub" } }