aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-06-24 16:50:07 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-06-24 16:50:07 -0700
commit9a2a4d5471baa159bfd4ed793962ec5d0841631b (patch)
tree7605618b39c12540ff266a53a05cd6c9ab08dfab /test/Transforms
parentc6ab023ee092501613e452bb850aa73ba7427857 (diff)
PNaCl ABI: Disallow built-in multiplication in "alloca" instructions
Simplify the set of "alloca" instructions the ABI verifier allows. Before this change, we used i8 arrays, such as: alloca [8 x i8] After this change, we will just use i8 with an explicit size value, so that becomes: alloca i8, i32 8 Allocation of variable-length arrays will require an explicit multiply instruction. This means that the code generator no longer has to handle an implicit multiplication in "alloca", reducing the burden on fast-and-simple code generators a little. This means the PNaCl ABI doesn't need to specify whether alloca's implicit multiplication checks for overflow. This doesn't affect what the backend generates. See lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp, which handles constant-size AllocaInsts (by filling out StaticAllocaMap) and which is uses for both -O2 (SelectionDAG) and -O0 (FastISel) translation. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3343 TEST=*.ll tests + PNaCl toolchain trybots Review URL: https://codereview.chromium.org/17631004
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/NaCl/replace-ptrs-with-ints.ll41
1 files changed, 27 insertions, 14 deletions
diff --git a/test/Transforms/NaCl/replace-ptrs-with-ints.ll b/test/Transforms/NaCl/replace-ptrs-with-ints.ll
index 823697d738..7761661798 100644
--- a/test/Transforms/NaCl/replace-ptrs-with-ints.ll
+++ b/test/Transforms/NaCl/replace-ptrs-with-ints.ll
@@ -352,8 +352,20 @@ define void @alloca_fixed() {
ret void
}
; CHECK: define void @alloca_fixed() {
-; CHECK-NEXT: %buf = alloca [8 x i8], align 128
-; CHECK-NEXT: %buf.asint = ptrtoint [8 x i8]* %buf to i32
+; CHECK-NEXT: %buf = alloca i8, i32 8, align 128
+; CHECK-NEXT: %buf.asint = ptrtoint i8* %buf to i32
+; CHECK-NEXT: call void @receive_alloca(i32 %buf.asint)
+
+; When the size passed to alloca is a constant, it should be a
+; constant in the output too.
+define void @alloca_fixed_array() {
+ %buf = alloca %struct, i32 100
+ call void @receive_alloca(%struct* %buf)
+ ret void
+}
+; CHECK: define void @alloca_fixed_array() {
+; CHECK-NEXT: %buf = alloca i8, i32 800, align 8
+; CHECK-NEXT: %buf.asint = ptrtoint i8* %buf to i32
; CHECK-NEXT: call void @receive_alloca(i32 %buf.asint)
define void @alloca_variable(i32 %size) {
@@ -362,8 +374,9 @@ define void @alloca_variable(i32 %size) {
ret void
}
; CHECK: define void @alloca_variable(i32 %size) {
-; CHECK-NEXT: %buf = alloca [8 x i8], i32 %size
-; CHECK-NEXT: %buf.asint = ptrtoint [8 x i8]* %buf to i32
+; CHECK-NEXT: %buf.alloca_mul = mul i32 8, %size
+; CHECK-NEXT: %buf = alloca i8, i32 %buf.alloca_mul
+; CHECK-NEXT: %buf.asint = ptrtoint i8* %buf to i32
; CHECK-NEXT: call void @receive_alloca(i32 %buf.asint)
define void @alloca_alignment_i32() {
@@ -371,21 +384,21 @@ define void @alloca_alignment_i32() {
ret void
}
; CHECK: void @alloca_alignment_i32() {
-; CHECK-NEXT: alloca [4 x i8], align 4
+; CHECK-NEXT: alloca i8, i32 4, align 4
define void @alloca_alignment_double() {
%buf = alloca double
ret void
}
; CHECK: void @alloca_alignment_double() {
-; CHECK-NEXT: alloca [8 x i8], align 8
+; CHECK-NEXT: alloca i8, i32 8, align 8
define void @alloca_lower_alignment() {
%buf = alloca i32, align 1
ret void
}
; CHECK: void @alloca_lower_alignment() {
-; CHECK-NEXT: alloca [4 x i8], align 1
+; CHECK-NEXT: alloca i8, i32 4, align 1
; This tests for a bug in which, when processing the store's %buf2
@@ -400,8 +413,8 @@ define void @alloca_cast_stripping() {
ret void
}
; CHECK: define void @alloca_cast_stripping() {
-; CHECK-NEXT: %buf = alloca [4 x i8]
-; CHECK-NEXT: %buf.bc = bitcast [4 x i8]* %buf to i32*
+; CHECK-NEXT: %buf = alloca i8, i32 4
+; CHECK-NEXT: %buf.bc = bitcast i8* %buf to i32*
; CHECK-NEXT: store i32 0, i32* %buf.bc
@@ -449,8 +462,8 @@ define void @debug_declare(i32 %val) {
ret void
}
; CHECK: define void @debug_declare(i32 %val) {
-; CHECK-NEXT: %var = alloca [4 x i8]
-; CHECK-NEXT: call void @llvm.dbg.declare(metadata !{[4 x i8]* %var}, metadata !0)
+; CHECK-NEXT: %var = alloca i8, i32 4
+; CHECK-NEXT: call void @llvm.dbg.declare(metadata !{i8* %var}, metadata !0)
; This case is currently not converted.
; CHECK-NEXT: call void @llvm.dbg.declare(metadata !{null}, metadata !0)
; CHECK-NEXT: ret void
@@ -498,7 +511,7 @@ define void @alloca_lifetime() {
ret void
}
; CHECK: define void @alloca_lifetime() {
-; CHECK-NEXT: %buf = alloca [1 x i8]
+; CHECK-NEXT: %buf = alloca i8
; CHECK-NEXT: ret void
define void @alloca_lifetime_via_bitcast() {
@@ -508,7 +521,7 @@ define void @alloca_lifetime_via_bitcast() {
ret void
}
; CHECK: define void @alloca_lifetime_via_bitcast() {
-; CHECK-NEXT: %buf = alloca [4 x i8]
+; CHECK-NEXT: %buf = alloca i8, i32 4
; CHECK-NEXT: ret void
define void @strip_invariant_markers() {
@@ -518,7 +531,7 @@ define void @strip_invariant_markers() {
ret void
}
; CHECK: define void @strip_invariant_markers() {
-; CHECK-NEXT: %buf = alloca [1 x i8]
+; CHECK-NEXT: %buf = alloca i8
; CHECK-NEXT: ret void