interp: work around AVR function pointers in globals

Not sure how to test this, since we don't really have any AVR tests
configured.
This commit is contained in:
Ayke van Laethem
2021-12-10 22:17:17 +01:00
committed by Ron Evans
parent 0f69d016a0
commit 3e6410f323
2 changed files with 10 additions and 1 deletions
+8 -1
View File
@@ -903,7 +903,14 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
return llvm.Value{}, err
}
if llvmValue.Type() != llvmType {
llvmValue = llvm.ConstBitCast(llvmValue, llvmType)
if llvmValue.Type().PointerAddressSpace() != llvmType.PointerAddressSpace() {
// Special case for AVR function pointers.
// Because go-llvm doesn't have addrspacecast at the moment,
// do it indirectly with a ptrtoint/inttoptr pair.
llvmValue = llvm.ConstIntToPtr(llvm.ConstPtrToInt(llvmValue, mem.r.uintptrType), llvmType)
} else {
llvmValue = llvm.ConstBitCast(llvmValue, llvmType)
}
}
return llvmValue, nil
}