Skip to content

Commit bece6b9

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent 553f00b commit bece6b9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

interp/interp.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ func Run(mod llvm.Module, targetData llvm.TargetData, debug bool) error {
6363
return errors.New("expected all instructions in " + name + " to be *.init() calls")
6464
}
6565
pkgName := initName[:len(initName)-5]
66-
_, err := e.Function(call.CalledValue(), []Value{&LocalValue{e, undefPtr}, &LocalValue{e, undefPtr}}, pkgName)
66+
fn := call.CalledValue()
67+
call.EraseFromParentAsInstruction()
68+
_, err := e.Function(fn, []Value{&LocalValue{e, undefPtr}, &LocalValue{e, undefPtr}}, pkgName)
6769
if err == ErrUnreachable {
6870
break
6971
}
7072
if err != nil {
7173
return err
7274
}
73-
call.EraseFromParentAsInstruction()
7475
}
7576

7677
return nil

0 commit comments

Comments
 (0)