mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
interp: align created globals
Use the alignment from the align attribute of the runtime.alloc call. This is going to be a more accurate alignment, and is typically smaller than the default.
This commit is contained in:
committed by
Ron Evans
parent
5f252b3e16
commit
ecc6d16f22
@@ -287,9 +287,17 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// Get the object layout, if it is available.
|
||||
llvmLayoutType := r.getLLVMTypeFromLayout(operands[2])
|
||||
|
||||
// Get the alignment of the memory to be allocated.
|
||||
alignment := 0 // use default alignment if unset
|
||||
alignAttr := inst.llvmInst.GetCallSiteEnumAttribute(0, llvm.AttributeKindID("align"))
|
||||
if !alignAttr.IsNil() {
|
||||
alignment = int(alignAttr.GetEnumValue())
|
||||
}
|
||||
|
||||
// Create the object.
|
||||
alloc := object{
|
||||
globalName: r.pkgName + "$alloc",
|
||||
align: alignment,
|
||||
llvmLayoutType: llvmLayoutType,
|
||||
buffer: newRawValue(uint32(size)),
|
||||
size: uint32(size),
|
||||
@@ -646,6 +654,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
globalName: r.pkgName + "$alloca",
|
||||
buffer: newRawValue(uint32(size)),
|
||||
size: uint32(size),
|
||||
align: inst.llvmInst.Alignment(),
|
||||
}
|
||||
index := len(r.objects)
|
||||
r.objects = append(r.objects, alloca)
|
||||
|
||||
Reference in New Issue
Block a user