aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-03-08 14:16:48 +0100
committerRon Evans <[email protected]>2021-03-22 11:35:06 +0100
commit2709d38d6370abcf099bb47edeb290ff0c263496 (patch)
treeb7660e9cbd6b49c81b5e6fe16cf6c279ce19d613
parent71d1b70ab7be5767d83093dc6b375cd02fdf64b3 (diff)
downloadtinygo-2709d38d6370abcf099bb47edeb290ff0c263496.tar.gz
tinygo-2709d38d6370abcf099bb47edeb290ff0c263496.zip
compiler: add some more slice tests
-rw-r--r--compiler/testdata/slice.go16
-rw-r--r--compiler/testdata/slice.ll93
2 files changed, 109 insertions, 0 deletions
diff --git a/compiler/testdata/slice.go b/compiler/testdata/slice.go
index 216fad4d2..f26d53d88 100644
--- a/compiler/testdata/slice.go
+++ b/compiler/testdata/slice.go
@@ -7,3 +7,19 @@ func sliceLen(ints []int) int {
func sliceCap(ints []int) int {
return cap(ints)
}
+
+func sliceElement(ints []int, index int) int {
+ return ints[index]
+}
+
+func sliceAppendValues(ints []int) []int {
+ return append(ints, 1, 2, 3)
+}
+
+func sliceAppendSlice(ints, added []int) []int {
+ return append(ints, added...)
+}
+
+func sliceCopy(dst, src []int) int {
+ return copy(dst, src)
+}
diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll
index 1fb054c55..4ff983a85 100644
--- a/compiler/testdata/slice.ll
+++ b/compiler/testdata/slice.ll
@@ -19,3 +19,96 @@ define hidden i32 @main.sliceCap(i32* %ints.data, i32 %ints.len, i32 %ints.cap,
entry:
ret i32 %ints.cap
}
+
+define hidden i32 @main.sliceElement(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, i8* %context, i8* %parentHandle) unnamed_addr {
+entry:
+ %.not = icmp ult i32 %index, %ints.len
+ br i1 %.not, label %lookup.next, label %lookup.throw
+
+lookup.throw: ; preds = %entry
+ call void @runtime.lookupPanic(i8* undef, i8* null)
+ unreachable
+
+lookup.next: ; preds = %entry
+ %0 = getelementptr inbounds i32, i32* %ints.data, i32 %index
+ %1 = load i32, i32* %0, align 4
+ ret i32 %1
+}
+
+declare void @runtime.lookupPanic(i8*, i8*)
+
+define hidden { i32*, i32, i32 } @main.sliceAppendValues(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context, i8* %parentHandle) unnamed_addr {
+entry:
+ %varargs = call i8* @runtime.alloc(i32 12, i8* undef, i8* null)
+ br i1 false, label %gep.throw, label %gep.next
+
+gep.throw: ; preds = %entry
+ unreachable
+
+gep.next: ; preds = %entry
+ %0 = bitcast i8* %varargs to i32*
+ store i32 1, i32* %0, align 4
+ br i1 false, label %gep.throw1, label %gep.next2
+
+gep.throw1: ; preds = %gep.next
+ unreachable
+
+gep.next2: ; preds = %gep.next
+ %1 = getelementptr inbounds i8, i8* %varargs, i32 4
+ %2 = bitcast i8* %1 to i32*
+ store i32 2, i32* %2, align 4
+ br i1 false, label %gep.throw3, label %gep.next4
+
+gep.throw3: ; preds = %gep.next2
+ unreachable
+
+gep.next4: ; preds = %gep.next2
+ %3 = getelementptr inbounds i8, i8* %varargs, i32 8
+ %4 = bitcast i8* %3 to i32*
+ store i32 3, i32* %4, align 4
+ br i1 false, label %slice.throw, label %slice.next
+
+slice.throw: ; preds = %gep.next4
+ unreachable
+
+slice.next: ; preds = %gep.next4
+ %append.srcPtr = bitcast i32* %ints.data to i8*
+ %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, i8* undef, i8* null)
+ %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0
+ %append.newBuf = bitcast i8* %append.newPtr to i32*
+ %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1
+ %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2
+ %5 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0
+ %6 = insertvalue { i32*, i32, i32 } %5, i32 %append.newLen, 1
+ %7 = insertvalue { i32*, i32, i32 } %6, i32 %append.newCap, 2
+ ret { i32*, i32, i32 } %7
+}
+
+declare void @runtime.nilPanic(i8*, i8*)
+
+declare { i8*, i32, i32 } @runtime.sliceAppend(i8*, i8*, i32, i32, i32, i32, i8*, i8*)
+
+define hidden { i32*, i32, i32 } @main.sliceAppendSlice(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32* %added.data, i32 %added.len, i32 %added.cap, i8* %context, i8* %parentHandle) unnamed_addr {
+entry:
+ %append.srcPtr = bitcast i32* %ints.data to i8*
+ %append.srcPtr1 = bitcast i32* %added.data to i8*
+ %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* %append.srcPtr1, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, i8* undef, i8* null)
+ %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0
+ %append.newBuf = bitcast i8* %append.newPtr to i32*
+ %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1
+ %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2
+ %0 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0
+ %1 = insertvalue { i32*, i32, i32 } %0, i32 %append.newLen, 1
+ %2 = insertvalue { i32*, i32, i32 } %1, i32 %append.newCap, 2
+ ret { i32*, i32, i32 } %2
+}
+
+define hidden i32 @main.sliceCopy(i32* %dst.data, i32 %dst.len, i32 %dst.cap, i32* %src.data, i32 %src.len, i32 %src.cap, i8* %context, i8* %parentHandle) unnamed_addr {
+entry:
+ %copy.dstPtr = bitcast i32* %dst.data to i8*
+ %copy.srcPtr = bitcast i32* %src.data to i8*
+ %copy.n = call i32 @runtime.sliceCopy(i8* %copy.dstPtr, i8* %copy.srcPtr, i32 %dst.len, i32 %src.len, i32 4, i8* undef, i8* null)
+ ret i32 %copy.n
+}
+
+declare i32 @runtime.sliceCopy(i8*, i8*, i32, i32, i32, i8*, i8*)