Skip to content

Commit d8ac7cc

Browse files
aykevldeadprogram
authored andcommitted
interp: fix a bug in pointer cast workaround
This was triggered by the following code: var smallPrimesProduct = new(big.Int).SetUint64(16294579238595022365) It is part of the new TinyGo version of the crypto/rand package.
1 parent 64058c3 commit d8ac7cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

interp/interp.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func Run(mod llvm.Module, debug bool) error {
129129

130130
// Update all global variables in the LLVM module.
131131
mem := memoryView{r: r}
132-
for _, obj := range r.objects {
132+
for i, obj := range r.objects {
133133
if obj.llvmGlobal.IsNil() {
134134
continue
135135
}
@@ -159,6 +159,12 @@ func Run(mod llvm.Module, debug bool) error {
159159
name := obj.llvmGlobal.Name()
160160
obj.llvmGlobal.EraseFromParentAsGlobal()
161161
newGlobal.SetName(name)
162+
163+
// Update interp-internal references.
164+
delete(r.globals, obj.llvmGlobal)
165+
obj.llvmGlobal = newGlobal
166+
r.globals[newGlobal] = i
167+
r.objects[i] = obj
162168
continue
163169
}
164170
if err != nil {

0 commit comments

Comments
 (0)