File: static_array_init.d

package info (click to toggle)
ldc 1%3A1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 53,728 kB
  • sloc: cpp: 55,939; ansic: 10,599; sh: 958; makefile: 801; asm: 507; objc: 122; exp: 30; python: 12
file content (112 lines) | stat: -rw-r--r-- 4,039 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// RUN: %ldc -output-ll %s -of=%t.ll
// RUN: FileCheck %s < %t.ll

void bytes_scalar()
{
    immutable(byte)[32] myBytes = 123;

    // CHECK:      define {{.*}}_D17static_array_init12bytes_scalarFZv
    // CHECK-NEXT:   %myBytes = alloca [32 x i8], align 1
    // CHECK-NEXT:   %1 = bitcast [32 x i8]* %myBytes to i8*
    // CHECK-NEXT:   call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 123, i{{(32|64)}} 32
}

void bytes_scalar(byte arg)
{
    immutable(byte)[32] myBytes = arg;

    // CHECK:      define {{.*}}_D17static_array_init12bytes_scalarFgZv
    // CHECK-NEXT:   %arg = alloca i8, align 1
    // CHECK-NEXT:   %myBytes = alloca [32 x i8], align 1
    // CHECK-NEXT:   store i8 %arg_arg, i8* %arg
    // CHECK-NEXT:   %1 = bitcast [32 x i8]* %myBytes to i8*
    // CHECK-NEXT:   %2 = load {{.*}}i8* %arg
    // CHECK-NEXT:   call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8 %2, i{{(32|64)}} 32
}

void ints_scalar()
{
    const(int[32]) myInts = 123;

    // CHECK:      define {{.*}}_D17static_array_init11ints_scalarFZv
    // CHECK:      arrayinit.cond:
    // CHECK-NEXT:   %[[I1:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr
    // CHECK-NEXT:   %arrayinit.condition = icmp ne i{{(32|64)}} %[[I1]], 32
    // CHECK:        store i32 123, i32* %arrayinit.arrayelem
}

void ints_scalar(int arg)
{
    const(int[32]) myInts = arg;

    // CHECK:      define {{.*}}_D17static_array_init11ints_scalarFiZv
    // CHECK:      arrayinit.cond:
    // CHECK-NEXT:   %[[I2:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr
    // CHECK-NEXT:   %arrayinit.condition = icmp ne i{{(32|64)}} %[[I2]], 32
    // CHECK:        %[[E2:[0-9]+]] = load {{.*}}i32* %arg
    // CHECK-NEXT:   store i32 %[[E2]], i32* %arrayinit.arrayelem
}

void bytes()
{
    immutable(byte[4]) myBytes = [ 1, 2, 3, 4 ];

    // CHECK:      define {{.*}}_D17static_array_init5bytesFZv
    // CHECK-NEXT:   %myBytes = alloca [4 x i8], align 1
    // CHECK-NEXT:   store [4 x i8] c"\01\02\03\04", [4 x i8]* %myBytes
}

void bytes(byte[] arg)
{
    const(byte)[4] myBytes = arg;

    // CHECK:      define {{.*}}_D17static_array_init5bytesFAgZv
    // CHECK:        %myBytes = alloca [4 x i8], align 1
    // CHECK:        %1 = bitcast [4 x i8]* %myBytes to i8*
    // CHECK:        call void @llvm.memcpy{{.*}}(i8*{{[a-z0-9 ]*}} %1, i8*{{[a-z0-9 ]*}} %.ptr, i{{(32|64)}} 4
}

void ints()
{
    immutable(int)[4] myInts = [ 1, 2, 3, 4 ];

    // CHECK:      define {{.*}}_D17static_array_init4intsFZv
    // CHECK-NEXT:   %myInts = alloca [4 x i32], align 4
    // CHECK-NEXT:   store [4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32]* %myInts
}

void ints(ref int[4] arg)
{
    const(int[4]) myInts = arg;

    // CHECK:      define {{.*}}_D17static_array_init4intsFKG4iZv
    // CHECK-NEXT:   %myInts = alloca [4 x i32], align 4
    // CHECK-NEXT:   %1 = bitcast [4 x i32]* %myInts to i32*
    // CHECK-NEXT:   %2 = bitcast i32* %1 to i8*
    // CHECK-NEXT:   %3 = bitcast [4 x i32]* %arg to i32*
    // CHECK-NEXT:   %4 = bitcast i32* %3 to i8*
    // CHECK-NEXT:   call void @llvm.memcpy{{.*}}(i8*{{[a-z0-9 ]*}} %2, i8*{{[a-z0-9 ]*}} %4, i{{(32|64)}} 16
}

void bytes_scalar_2d()
{
    immutable(byte)[4][8] myBytes = 123;

    // CHECK:      define {{.*}}_D17static_array_init15bytes_scalar_2dFZv
    // CHECK-NEXT:   %myBytes = alloca [8 x [4 x i8]], align 1
    // CHECK-NEXT:   %1 = bitcast [8 x [4 x i8]]* %myBytes to [32 x i8]*
    // CHECK-NEXT:   %2 = bitcast [32 x i8]* %1 to i8*
    // CHECK-NEXT:   call void @llvm.memset{{.*}}(i8*{{[a-z0-9 ]*}} %2, i8 123, i{{(32|64)}} 32
}

void ints_scalar_2d(immutable int arg)
{
    const(int[4])[8] myInts = arg;

    // CHECK:      define {{.*}}_D17static_array_init14ints_scalar_2dFyiZv
    // CHECK:      arrayinit.cond:
    // CHECK-NEXT:   %[[I3:[0-9]+]] = load {{.*i(32|64)}}* %arrayinit.itr
    // CHECK-NEXT:   %arrayinit.condition = icmp ne i{{(32|64)}} %[[I3]], 32
    // CHECK:        %[[E3:[0-9]+]] = load {{.*}}i32* %arg
    // CHECK-NEXT:   store i32 %[[E3]], i32* %arrayinit.arrayelem
}