mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
interp: don't ignore array indices for untyped objects
This fixes https://github.com/tinygo-org/tinygo/issues/1884. My original plan to fix this was much more complicated, but then I realized that the output type doesn't matter anyway and I can simply cast the type to an *i8 and perform a GEP on that pointer.
This commit is contained in:
committed by
Ron Evans
parent
0565b7c0e0
commit
cdba4fa8cc
+1
-1
@@ -15,7 +15,7 @@ import (
|
||||
// package is changed in a way that affects the output so that cached package
|
||||
// builds will be invalidated.
|
||||
// This version is independent of the TinyGo version number.
|
||||
const Version = 1
|
||||
const Version = 2 // last change: fix GEP on untyped pointers
|
||||
|
||||
// Enable extra checks, which should be disabled by default.
|
||||
// This may help track down bugs by adding a few more sanity checks.
|
||||
|
||||
@@ -572,6 +572,17 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
|
||||
}
|
||||
|
||||
if llvmType.IsNil() {
|
||||
if v.offset() != 0 {
|
||||
// If there is an offset, make sure to use a GEP to index into the
|
||||
// pointer. Because there is no expected type, we use whatever is
|
||||
// most convenient: an *i8 type. It is trivial to index byte-wise.
|
||||
if llvmValue.Type() != mem.r.i8ptrType {
|
||||
llvmValue = llvm.ConstBitCast(llvmValue, mem.r.i8ptrType)
|
||||
}
|
||||
llvmValue = llvm.ConstInBoundsGEP(llvmValue, []llvm.Value{
|
||||
llvm.ConstInt(llvmValue.Type().Context().Int32Type(), uint64(v.offset()), false),
|
||||
})
|
||||
}
|
||||
return llvmValue, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user