File: func_contracts_gh1543.d

package info (click to toggle)
ldc 1%3A1.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 80,880 kB
  • sloc: ansic: 123,899; cpp: 84,038; sh: 1,402; makefile: 1,083; asm: 919; objc: 65; exp: 30; python: 22
file content (52 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (3)
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
// Test the combination of `out` arguments with in- and out-contracts.

// Github issue #1543, https://github.com/ldc-developers/ldc/issues/1543

// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
// RUN: %ldc -run %s

module mod;

class Bar
{
    void failMe(out int some)
    in
    {
        assert(some == 0);
    }
    out
    {
        assert(some == 123);
    }
    body
    {
        some = 123;
    }
}

// Bar.failMe codegen order = function, in-contract __require function, out-contract __ensure function

// CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMe
// CHECK-SAME: i32* dereferenceable(4) %some
// CHECK: store i32 0, i32* %some
// CHECK: call {{.*}} @{{.*}}Bar6failMeMFJiZ9__require
// CHECK: call {{.*}} @{{.*}}Bar6failMeMFJiZ8__ensure
// CHECK: }

// CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMeMFJiZ9__require
// CHECK-SAME: i32* dereferenceable(4) %some
// CHECK-NOT: store {{.*}} %some
// CHECK: }

// CHECK-LABEL: define {{.*}} @{{.*}}Bar6failMeMFJiZ8__ensure
// CHECK-SAME: i32* dereferenceable(4) %some
// CHECK-NOT: store {{.*}} %some
// CHECK: }

void main()
{
    int some;
    auto b = new Bar;
    b.failMe(some);
    assert(some == 123);
}