Skip to content

Commit 097fef2

Browse files
authored
[SPIRV] Fix asan failure (#138695)
When the DataLayout is destroyed, the memory backing `Offsets` is released. This causes a use after free. To fix it, I added a DataLayout varible that will not be destroyed until after Offsets is used. Fixes asan failure caused by #135789
1 parent 57e8899 commit 097fef2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,8 +2062,8 @@ void SPIRVGlobalRegistry::updateAssignType(CallInst *AssignCI, Value *Arg,
20622062

20632063
void SPIRVGlobalRegistry::addStructOffsetDecorations(
20642064
Register Reg, StructType *Ty, MachineIRBuilder &MIRBuilder) {
2065-
ArrayRef<TypeSize> Offsets =
2066-
DataLayout().getStructLayout(Ty)->getMemberOffsets();
2065+
DataLayout DL;
2066+
ArrayRef<TypeSize> Offsets = DL.getStructLayout(Ty)->getMemberOffsets();
20672067
for (uint32_t I = 0; I < Ty->getNumElements(); ++I) {
20682068
buildOpMemberDecorate(Reg, MIRBuilder, SPIRV::Decoration::Offset, I,
20692069
{static_cast<uint32_t>(Offsets[I])});

0 commit comments

Comments
 (0)