@@ -7,46 +7,61 @@ declare nonnull ptr @runtime.alloc(i32, ptr)
7
7
8
8
; Test allocating a single int (i32) that should be allocated on the stack.
9
9
define void @testInt () {
10
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
10
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
11
11
store i32 5 , ptr %alloc
12
12
ret void
13
13
}
14
14
15
15
; Test allocating an array of 3 i16 values that should be allocated on the
16
16
; stack.
17
17
define i16 @testArray () {
18
- %alloc = call ptr @runtime.alloc (i32 6 , ptr null )
18
+ %alloc = call align 2 ptr @runtime.alloc (i32 6 , ptr null )
19
19
%alloc.1 = getelementptr i16 , ptr %alloc , i32 1
20
20
store i16 5 , ptr %alloc.1
21
21
%alloc.2 = getelementptr i16 , ptr %alloc , i32 2
22
22
%val = load i16 , ptr %alloc.2
23
23
ret i16 %val
24
24
}
25
25
26
+ ; Test allocating objects with an unknown alignment.
27
+ define void @testUnknownAlign () {
28
+ %alloc32 = call ptr @runtime.alloc (i32 32 , ptr null )
29
+ store i8 5 , ptr %alloc32
30
+ %alloc24 = call ptr @runtime.alloc (i32 24 , ptr null )
31
+ store i16 5 , ptr %alloc24
32
+ %alloc12 = call ptr @runtime.alloc (i32 12 , ptr null )
33
+ store i16 5 , ptr %alloc12
34
+ %alloc6 = call ptr @runtime.alloc (i32 6 , ptr null )
35
+ store i16 5 , ptr %alloc6
36
+ %alloc3 = call ptr @runtime.alloc (i32 3 , ptr null )
37
+ store i16 5 , ptr %alloc3
38
+ ret void
39
+ }
40
+
26
41
; Call a function that will let the pointer escape, so the heap-to-stack
27
42
; transform shouldn't be applied.
28
43
define void @testEscapingCall () {
29
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
44
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
30
45
%val = call ptr @escapeIntPtr (ptr %alloc )
31
46
ret void
32
47
}
33
48
34
49
define void @testEscapingCall2 () {
35
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
50
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
36
51
%val = call ptr @escapeIntPtrSometimes (ptr %alloc , ptr %alloc )
37
52
ret void
38
53
}
39
54
40
55
; Call a function that doesn't let the pointer escape.
41
56
define void @testNonEscapingCall () {
42
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
57
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
43
58
%val = call ptr @noescapeIntPtr (ptr %alloc )
44
59
ret void
45
60
}
46
61
47
62
; Return the allocated value, which lets it escape.
48
63
define ptr @testEscapingReturn () {
49
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
64
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
50
65
ret ptr %alloc
51
66
}
52
67
@@ -55,7 +70,7 @@ define void @testNonEscapingLoop() {
55
70
entry:
56
71
br label %loop
57
72
loop:
58
- %alloc = call ptr @runtime.alloc (i32 4 , ptr null )
73
+ %alloc = call align 4 ptr @runtime.alloc (i32 4 , ptr null )
59
74
%ptr = call ptr @noescapeIntPtr (ptr %alloc )
60
75
%result = icmp eq ptr null , %ptr
61
76
br i1 %result , label %loop , label %end
65
80
66
81
; Test a zero-sized allocation.
67
82
define void @testZeroSizedAlloc () {
68
- %alloc = call ptr @runtime.alloc (i32 0 , ptr null )
83
+ %alloc = call align 1 ptr @runtime.alloc (i32 0 , ptr null )
69
84
%ptr = call ptr @noescapeIntPtr (ptr %alloc )
70
85
ret void
71
86
}
0 commit comments