[llvm] 097fef2 - [SPIRV] Fix asan failure (#138695)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 6 14:50:21 PDT 2025


Author: Steven Perron
Date: 2025-05-06T17:50:17-04:00
New Revision: 097fef28dae145cc41f80151825e929668414d24

URL: https://github.com/llvm/llvm-project/commit/097fef28dae145cc41f80151825e929668414d24
DIFF: https://github.com/llvm/llvm-project/commit/097fef28dae145cc41f80151825e929668414d24.diff

LOG: [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
https://github.com/llvm/llvm-project/pull/135789

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 35ddb906c366a..ad42c73e24333 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -2062,8 +2062,8 @@ void SPIRVGlobalRegistry::updateAssignType(CallInst *AssignCI, Value *Arg,
 
 void SPIRVGlobalRegistry::addStructOffsetDecorations(
     Register Reg, StructType *Ty, MachineIRBuilder &MIRBuilder) {
-  ArrayRef<TypeSize> Offsets =
-      DataLayout().getStructLayout(Ty)->getMemberOffsets();
+  DataLayout DL;
+  ArrayRef<TypeSize> Offsets = DL.getStructLayout(Ty)->getMemberOffsets();
   for (uint32_t I = 0; I < Ty->getNumElements(); ++I) {
     buildOpMemberDecorate(Reg, MIRBuilder, SPIRV::Decoration::Offset, I,
                           {static_cast<uint32_t>(Offsets[I])});


        


More information about the llvm-commits mailing list