aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-02-04 13:14:06 +0100
committerRon Evans <[email protected]>2019-02-05 17:37:55 +0100
commitbece6b964890e6b6ef2523f436717605551e4d7a (patch)
tree135080172a0f268349c417d1c7b8762730ccf620
parent553f00bdb8ed3bee54e8be8dacc4ab4994455189 (diff)
downloadtinygo-bece6b964890e6b6ef2523f436717605551e4d7a.tar.gz
tinygo-bece6b964890e6b6ef2523f436717605551e4d7a.zip
interp: remove init call when hitting 'unreachable'
The interp package interprets calls in runtime.initAll and replaces these calls with non-interpretable instructions if needed. When hitting an unreachable instruction, this call should be removed, but it wasn't. This commit makes sure the call is removed even before trying to interpret the package init function.
-rw-r--r--interp/interp.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/interp/interp.go b/interp/interp.go
index db7797c2d..7328170a0 100644
--- a/interp/interp.go
+++ b/interp/interp.go
@@ -63,14 +63,15 @@ func Run(mod llvm.Module, targetData llvm.TargetData, debug bool) error {
return errors.New("expected all instructions in " + name + " to be *.init() calls")
}
pkgName := initName[:len(initName)-5]
- _, err := e.Function(call.CalledValue(), []Value{&LocalValue{e, undefPtr}, &LocalValue{e, undefPtr}}, pkgName)
+ fn := call.CalledValue()
+ call.EraseFromParentAsInstruction()
+ _, err := e.Function(fn, []Value{&LocalValue{e, undefPtr}, &LocalValue{e, undefPtr}}, pkgName)
if err == ErrUnreachable {
break
}
if err != nil {
return err
}
- call.EraseFromParentAsInstruction()
}
return nil