Skip to content

Commit

Permalink
Resolve static analyser report on pointer dereferencing after null ch…
Browse files Browse the repository at this point in the history
…eck (llvm#88278)

- Resolve Static Analyzer Check Failure: Pointer Dereferencing After
Null Check.
- Minor naming and style improvement

Change-Id: I970ef318ffbde90c779c3e9b1336f3cd76cd5c4d
  • Loading branch information
mmoadeli authored and JeniferC99 committed Sep 3, 2024
1 parent deb79e4 commit 1c7a195
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,43 +1034,40 @@ class AMDGPULowerModuleLDS {
void removeNoLdsKernelIdFromReachable(CallGraph &CG, Function *KernelRoot) {
KernelRoot->removeFnAttr("amdgpu-no-lds-kernel-id");

SmallVector<Function *> Tmp({CG[KernelRoot]->getFunction()});
if (!Tmp.back())
return;

SmallVector<Function *> WorkList({CG[KernelRoot]->getFunction()});
SmallPtrSet<Function *, 8> Visited;
bool SeenUnknownCall = false;

do {
Function *F = Tmp.pop_back_val();
while (!WorkList.empty()) {
Function *F = WorkList.pop_back_val();

for (auto &N : *CG[F]) {
if (!N.second)
for (auto &CallRecord : *CG[F]) {
if (!CallRecord.second)
continue;

Function *Callee = N.second->getFunction();
Function *Callee = CallRecord.second->getFunction();
if (!Callee) {
if (!SeenUnknownCall) {
SeenUnknownCall = true;

// If we see any indirect calls, assume nothing about potential
// targets.
// TODO: This could be refined to possible LDS global users.
for (auto &N : *CG.getExternalCallingNode()) {
Function *PotentialCallee = N.second->getFunction();
for (auto &ExternalCallRecord : *CG.getExternalCallingNode()) {
Function *PotentialCallee =
ExternalCallRecord.second->getFunction();
assert(PotentialCallee);
if (!isKernelLDS(PotentialCallee))
PotentialCallee->removeFnAttr("amdgpu-no-lds-kernel-id");
}

continue;
}
} else {
Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
if (Visited.insert(Callee).second)
WorkList.push_back(Callee);
}

Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
if (Visited.insert(Callee).second)
Tmp.push_back(Callee);
}
} while (!Tmp.empty());
}
}

DenseMap<Function *, GlobalVariable *> lowerDynamicLDSVariables(
Expand Down

0 comments on commit 1c7a195

Please sign in to comment.