Skip to content

Commit 09f7b17

Browse files
committed
ir: add explicit AddrSpace field for optional address space of InstAlloca
Prior to this commit, the AddrSpace was stored in the cached result pointer type of InstAlloca (i.e. in the Typ field). However, this approach was fragile as resetting the type cache would remove the information about address space.
1 parent a826a98 commit 09f7b17

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

asm/inst_memory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (fgen *funcGen) irAllocaInst(new ir.Instruction, old *ast.AllocaInst) error
117117
}
118118
// (optional) Address space; stored in i.Typ.
119119
if n, ok := old.AddrSpace(); ok {
120-
inst.Typ.AddrSpace = irAddrSpace(n)
120+
inst.AddrSpace = irAddrSpace(n)
121121
}
122122
// (optional) Metadata.
123123
md, err := fgen.gen.irMetadataAttachments(old.Metadata())

ir/inst_memory.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type InstAlloca struct {
3535
SwiftError bool
3636
// (optional) Alignment; zero if not present.
3737
Align Align
38+
// (optional) Address space; zero if not present.
39+
AddrSpace types.AddrSpace
3840
// (optional) Metadata.
3941
Metadata
4042
}
@@ -58,6 +60,7 @@ func (inst *InstAlloca) Type() types.Type {
5860
// Cache type if not present.
5961
if inst.Typ == nil {
6062
inst.Typ = types.NewPointer(inst.ElemType)
63+
inst.Typ.AddrSpace = inst.AddrSpace
6164
}
6265
return inst.Typ
6366
}
@@ -82,8 +85,8 @@ func (inst *InstAlloca) LLString() string {
8285
if inst.Align != 0 {
8386
fmt.Fprintf(buf, ", %s", inst.Align)
8487
}
85-
if inst.Typ.AddrSpace != 0 {
86-
fmt.Fprintf(buf, ", %s", inst.Typ.AddrSpace)
88+
if inst.AddrSpace != 0 {
89+
fmt.Fprintf(buf, ", %s", inst.AddrSpace)
8790
}
8891
for _, md := range inst.Metadata {
8992
fmt.Fprintf(buf, ", %s", md)

0 commit comments

Comments
 (0)