-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[SPIRV] Fix asan failure #138695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIRV] Fix asan failure #138695
Conversation
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
@llvm/pr-subscribers-backend-spir-v Author: Steven Perron (s-perron) ChangesWhen the DataLayout is destroyed, the memory backing To fix it, I added a DataLayout varible that will not be destroyed until Fixes asan failure caused by #135789 Full diff: https://github.com/llvm/llvm-project/pull/138695.diff 1 Files Affected:
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 35ddb906c366a..948869d5c5260 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -2062,8 +2062,9 @@ void SPIRVGlobalRegistry::updateAssignType(CallInst *AssignCI, Value *Arg,
void SPIRVGlobalRegistry::addStructOffsetDecorations(
Register Reg, StructType *Ty, MachineIRBuilder &MIRBuilder) {
+ DataLayout DL;
ArrayRef<TypeSize> Offsets =
- DataLayout().getStructLayout(Ty)->getMemberOffsets();
+ 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])});
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Breaks bot: https://lab.llvm.org/buildbot/#/builders/24/builds/8151 This reverts commit 097fef2.
@s-perron I reverted this and the other related change FYI... |
The asan failure was fixed by llvm#138695, but another failure was introduced in the meantime. The cause for the other failure has been fixed. I will reapply the two PRs. Reapply "[SPIRV] Add explicit layout (llvm#135789)" This reverts commit 0fb5720. Reapply "[SPIRV] Fix asan failure (llvm#138695)" This reverts commit df90ab9.
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
Breaks bot: https://lab.llvm.org/buildbot/#/builders/24/builds/8151 This reverts commit 097fef2.
The asan failure was fixed by #138695, but another failure was introduced in the meantime. The cause for the other failure has been fixed. I will reapply the two PRs. Reapply "[SPIRV] Add explicit layout (#135789)" This reverts commit 0fb5720. Reapply "[SPIRV] Fix asan failure (#138695)" This reverts commit df90ab9.
When the DataLayout is destroyed, the memory backing
Offsets
isreleased. 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