summaryrefslogtreecommitdiff
path: root/tests/test/opt/twpo5.pp
blob: 920864e623eddccfc800c74007a98ee65b9f5375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ %target=darwin,linux,freebsd,solaris,aix,haiku }
{ %wpoparas=devirtcalls,optvmts,symbolliveness }
{ %wpopasses=2 }
{ %opt=-CX -XX -Xs- -g- }

{ -g- because DWARF debug info does not work with smart linking }

{ not enabled for windows yet because symbolliveness doesn't work there without
  installing "nm" (until implemented by way of internal linker there)
}

{$mode objfpc}

{ test case that can be optimised based on taking into account dead code
  stripping
}

type
  tbase = class
    procedure test; virtual;
  end;

  tchild1 = class(tbase)
    procedure test; override;
  end;

  tchild2 = class(tbase)
    procedure test; override;
  end;

procedure tbase.test;
begin
  halt(1);
end;

var
  a: longint;
  cc: class of tbase;

procedure tchild1.test;
begin
  if a<>1 then
    halt(2);
end;

procedure tchild2.test;
begin
  if a<>2 then
    halt(3);
end;

procedure notcalled;
var
  bb: tbase;
begin
  cc:=tchild2;
  bb:=cc.create;
  bb.test;
  bb.free;
end;

var
  bb: tbase;
begin
  cc:=tchild1;
  bb:=cc.create;
  a:=1;
  bb.test;
  a:=2;
  bb.free;
end.