Skip to content

Commit 4e49ba5

Browse files
committed
interrupt: fix bug in interrupt lowering
The alignment wasn't set, so defaulted to 4 (for a 32-bit int). LLVM saw this, and therefore assumed that a ptrtoint of the pointer would have had the lowest bits unset. That's an entirely valid optimization, except that we are using these globals for arbitrary values (and aren't actually using these globals). Fixed by setting alignment to 1. It works, though long-term we should maybe find a different solution for this.
1 parent 4b706ae commit 4e49ba5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/interrupt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro
4141

4242
// Create a new global of type runtime/interrupt.handle. Globals of this
4343
// type are lowered in the interrupt lowering pass.
44+
// It must have an alignment of 1, otherwise LLVM thinks a ptrtoint of the
45+
// global has the lower bits unset.
4446
globalType := b.program.ImportedPackage("runtime/interrupt").Type("handle").Type()
4547
globalLLVMType := b.getLLVMType(globalType)
4648
globalName := b.fn.Package().Pkg.Path() + "$interrupt" + strconv.FormatInt(id.Int64(), 10)
4749
global := llvm.AddGlobal(b.mod, globalLLVMType, globalName)
4850
global.SetVisibility(llvm.HiddenVisibility)
4951
global.SetGlobalConstant(true)
5052
global.SetUnnamedAddr(true)
53+
global.SetAlignment(1)
5154
initializer := llvm.ConstNull(globalLLVMType)
5255
initializer = b.CreateInsertValue(initializer, funcContext, 0, "")
5356
initializer = b.CreateInsertValue(initializer, funcPtr, 1, "")

0 commit comments

Comments
 (0)