[llvm] [WIP] Introduce address sanitizer instrumentation for LDS lowered by amdgpu-sw-lower-lds pass (PR #89208)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 03:52:42 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 472b612ccbeda470fa15005e11882349b0b384be fe15d89914845f40c03327babd7cba645aa3442b -- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index a24f26eada..d22a2cc379 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1396,66 +1396,71 @@ static void UpdateSwLDSMetadataWithRedzoneInfo(Function &F, int Scale) {
return;
}
-static void poisonRedzonesForSwLDS(Function& F) {
+static void poisonRedzonesForSwLDS(Function &F) {
Module *M = F.getParent();
GlobalVariable *SwLDSGlobal = getKernelSwLDSGlobal(*M, F);
GlobalVariable *SwLDSMetadataGlobal = getKernelSwLDSMetadataGlobal(*M, F);
-
- if (!SwLDSGlobal || !SwLDSMetadataGlobal) return;
+
+ if (!SwLDSGlobal || !SwLDSMetadataGlobal)
+ return;
LLVMContext &Ctx = M->getContext();
Type *Int64Ty = Type::getInt64Ty(Ctx);
Type *VoidTy = Type::getVoidTy(Ctx);
FunctionCallee AsanPoisonRegion = M->getOrInsertFunction(
- StringRef("__asan_poison_region"),
- FunctionType::get(VoidTy,
- {Int64Ty, Int64Ty}, false));
+ StringRef("__asan_poison_region"),
+ FunctionType::get(VoidTy, {Int64Ty, Int64Ty}, false));
Constant *MdInit = SwLDSMetadataGlobal->getInitializer();
- for (User *U : SwLDSGlobal->users()) {
+ for (User *U : SwLDSGlobal->users()) {
StoreInst *SI = dyn_cast<StoreInst>(U);
- if (!SI) continue;
-
- // Check if the value being stored is the result of a malloc
+ if (!SI)
+ continue;
+
+ // Check if the value being stored is the result of a malloc
CallInst *CI = dyn_cast<CallInst>(SI->getValueOperand());
- if (!CI) continue;
-
- Function *F = CI->getCalledFunction();
+ if (!CI)
+ continue;
+
+ Function *F = CI->getCalledFunction();
if (!F && !(F->getName() == "malloc"))
continue;
StructType *MDStructType =
- cast<StructType>(SwLDSMetadataGlobal->getValueType());
+ cast<StructType>(SwLDSMetadataGlobal->getValueType());
assert(MDStructType);
unsigned NumStructs = MDStructType->getNumElements();
- Value* StoreMallocPointer = SI->getValueOperand();
+ Value *StoreMallocPointer = SI->getValueOperand();
for (unsigned i = 0; i < NumStructs; i++) {
- ConstantStruct *member = dyn_cast<ConstantStruct>(MdInit->getAggregateElement(i));
- if (!member) continue;
+ ConstantStruct *member =
+ dyn_cast<ConstantStruct>(MdInit->getAggregateElement(i));
+ if (!member)
+ continue;
ConstantInt *GlobalSize =
cast<ConstantInt>(member->getAggregateElement(1U));
unsigned GlobalSizeValue = GlobalSize->getZExtValue();
-
- if (!GlobalSizeValue) continue;
+
+ if (!GlobalSizeValue)
+ continue;
IRBuilder<> IRB(SI);
IRB.SetInsertPoint(SI->getNextNode());
auto *GEPForOffset = IRB.CreateInBoundsGEP(
- MDStructType, SwLDSMetadataGlobal,
- {IRB.getInt32(0), IRB.getInt32(i), IRB.getInt32(2)});
+ MDStructType, SwLDSMetadataGlobal,
+ {IRB.getInt32(0), IRB.getInt32(i), IRB.getInt32(2)});
auto *GEPForSize = IRB.CreateInBoundsGEP(
- MDStructType, SwLDSMetadataGlobal,
- {IRB.getInt32(0), IRB.getInt32(i), IRB.getInt32(3)});
-
- Value *RedzoneOffset =
- IRB.CreateLoad(IRB.getInt64Ty(), GEPForOffset);
- Value* RedzoneAddrOffset = IRB.CreateInBoundsGEP(
- IRB.getInt8Ty(), StoreMallocPointer, {RedzoneOffset});
- Value* RedzoneAddress = IRB.CreatePtrToInt(RedzoneAddrOffset, IRB.getInt64Ty());
- Value *Redzonesize = IRB.CreateLoad(IRB.getInt64Ty(), GEPForSize);
+ MDStructType, SwLDSMetadataGlobal,
+ {IRB.getInt32(0), IRB.getInt32(i), IRB.getInt32(3)});
+
+ Value *RedzoneOffset = IRB.CreateLoad(IRB.getInt64Ty(), GEPForOffset);
+ Value *RedzoneAddrOffset = IRB.CreateInBoundsGEP(
+ IRB.getInt8Ty(), StoreMallocPointer, {RedzoneOffset});
+ Value *RedzoneAddress =
+ IRB.CreatePtrToInt(RedzoneAddrOffset, IRB.getInt64Ty());
+ Value *Redzonesize = IRB.CreateLoad(IRB.getInt64Ty(), GEPForSize);
IRB.CreateCall(AsanPoisonRegion, {RedzoneAddress, Redzonesize});
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/89208
More information about the llvm-commits
mailing list