aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-11 03:35:13 +0100
committerRon Evans <[email protected]>2021-11-11 10:36:22 +0100
commit6c02b4956cab4ebcb36d39fe9ff0cb646e120639 (patch)
tree83f5e432dfea5366c0cd607cf1b4d8c89bc21bc7 /interp
parent1681ed02d3035f3216885d560433bc1ad953ed24 (diff)
downloadtinygo-6c02b4956cab4ebcb36d39fe9ff0cb646e120639.tar.gz
tinygo-6c02b4956cab4ebcb36d39fe9ff0cb646e120639.zip
interp: fix reverting of extractvalue/insertvalue with multiple indices
Diffstat (limited to 'interp')
-rw-r--r--interp/interpreter.go5
-rw-r--r--interp/testdata/revert.ll11
-rw-r--r--interp/testdata/revert.out.ll7
3 files changed, 23 insertions, 0 deletions
diff --git a/interp/interpreter.go b/interp/interpreter.go
index a691e975c..304f65175 100644
--- a/interp/interpreter.go
+++ b/interp/interpreter.go
@@ -941,6 +941,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me
agg := operands[0]
for i := 0; i < len(indices)-1; i++ {
agg = r.builder.CreateExtractValue(agg, int(indices[i]), inst.name+".agg")
+ mem.instructions = append(mem.instructions, agg)
}
result = r.builder.CreateExtractValue(agg, int(indices[len(indices)-1]), inst.name)
case llvm.InsertValue:
@@ -953,11 +954,15 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me
for i := 0; i < len(indices)-1; i++ {
agg = r.builder.CreateExtractValue(agg, int(indices[i]), inst.name+".agg"+strconv.Itoa(i))
aggregates = append(aggregates, agg)
+ mem.instructions = append(mem.instructions, agg)
}
result = operands[1]
for i := len(indices) - 1; i >= 0; i-- {
agg := aggregates[i]
result = r.builder.CreateInsertValue(agg, result, int(indices[i]), inst.name+".insertvalue"+strconv.Itoa(i))
+ if i != 0 { // don't add last result to mem.instructions as it will be done at the end already
+ mem.instructions = append(mem.instructions, result)
+ }
}
case llvm.Add:
diff --git a/interp/testdata/revert.ll b/interp/testdata/revert.ll
index 41fb6a81e..d2b3007dd 100644
--- a/interp/testdata/revert.ll
+++ b/interp/testdata/revert.ll
@@ -5,9 +5,12 @@ declare void @externalCall(i64)
@foo.knownAtRuntime = global i64 0
@bar.knownAtRuntime = global i64 0
[email protected] = external global [3 x {i64, i32}]
[email protected] = global i32 0
define void @runtime.initAll() unnamed_addr {
entry:
+ call void @baz.init(i8* undef, i8* undef)
call void @foo.init(i8* undef, i8* undef)
call void @bar.init(i8* undef, i8* undef)
call void @main.init(i8* undef, i8* undef)
@@ -25,6 +28,14 @@ define internal void @bar.init(i8* %context, i8* %parentHandle) unnamed_addr {
ret void
}
+define internal void @baz.init(i8* %context, i8* %parentHandle) unnamed_addr {
+ ; Test extractvalue/insertvalue with more than one index.
+ %val = load [3 x {i64, i32}], [3 x {i64, i32}]* @baz.someGlobal
+ %part = extractvalue [3 x {i64, i32}] %val, 0, 1
+ %val2 = insertvalue [3 x {i64, i32}] %val, i32 5, 2, 1
+ unreachable ; trigger revert
+}
+
define internal void @main.init(i8* %context, i8* %parentHandle) unnamed_addr {
entry:
call void @externalCall(i64 3)
diff --git a/interp/testdata/revert.out.ll b/interp/testdata/revert.out.ll
index 4f38e4c41..edc474d5f 100644
--- a/interp/testdata/revert.out.ll
+++ b/interp/testdata/revert.out.ll
@@ -3,11 +3,14 @@ target triple = "x86_64--linux"
@foo.knownAtRuntime = local_unnamed_addr global i64 0
@bar.knownAtRuntime = local_unnamed_addr global i64 0
[email protected] = external local_unnamed_addr global [3 x { i64, i32 }]
[email protected] = local_unnamed_addr global i32 0
declare void @externalCall(i64) local_unnamed_addr
define void @runtime.initAll() unnamed_addr {
entry:
+ call fastcc void @baz.init(i8* undef, i8* undef)
call fastcc void @foo.init(i8* undef, i8* undef)
%val = load i64, i64* @foo.knownAtRuntime, align 8
store i64 %val, i64* @bar.knownAtRuntime, align 8
@@ -19,3 +22,7 @@ define internal fastcc void @foo.init(i8* %context, i8* %parentHandle) unnamed_a
store i64 5, i64* @foo.knownAtRuntime, align 8
unreachable
}
+
+define internal fastcc void @baz.init(i8* %context, i8* %parentHandle) unnamed_addr {
+ unreachable
+}