Skip to content

Commit 7cb0de3

Browse files
committed
[SPIRV] Fix asan failure
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 llvm#135789
1 parent 24cd3a0 commit 7cb0de3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

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

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

0 commit comments

Comments
 (0)