Skip to content

Commit 1c63a3e

Browse files
authored
Resolve static analyser report on pointer dereferencing after null check (#88278)
- Resolve Static Analyzer Check Failure: Pointer Dereferencing After Null Check. - Minor naming and style improvement
1 parent b4776b8 commit 1c63a3e

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,43 +1052,40 @@ class AMDGPULowerModuleLDS {
10521052
void removeNoLdsKernelIdFromReachable(CallGraph &CG, Function *KernelRoot) {
10531053
KernelRoot->removeFnAttr("amdgpu-no-lds-kernel-id");
10541054

1055-
SmallVector<Function *> Tmp({CG[KernelRoot]->getFunction()});
1056-
if (!Tmp.back())
1057-
return;
1058-
1055+
SmallVector<Function *> WorkList({CG[KernelRoot]->getFunction()});
10591056
SmallPtrSet<Function *, 8> Visited;
10601057
bool SeenUnknownCall = false;
10611058

1062-
do {
1063-
Function *F = Tmp.pop_back_val();
1059+
while (!WorkList.empty()) {
1060+
Function *F = WorkList.pop_back_val();
10641061

1065-
for (auto &N : *CG[F]) {
1066-
if (!N.second)
1062+
for (auto &CallRecord : *CG[F]) {
1063+
if (!CallRecord.second)
10671064
continue;
10681065

1069-
Function *Callee = N.second->getFunction();
1066+
Function *Callee = CallRecord.second->getFunction();
10701067
if (!Callee) {
10711068
if (!SeenUnknownCall) {
10721069
SeenUnknownCall = true;
10731070

10741071
// If we see any indirect calls, assume nothing about potential
10751072
// targets.
10761073
// TODO: This could be refined to possible LDS global users.
1077-
for (auto &N : *CG.getExternalCallingNode()) {
1078-
Function *PotentialCallee = N.second->getFunction();
1074+
for (auto &ExternalCallRecord : *CG.getExternalCallingNode()) {
1075+
Function *PotentialCallee =
1076+
ExternalCallRecord.second->getFunction();
1077+
assert(PotentialCallee);
10791078
if (!isKernelLDS(PotentialCallee))
10801079
PotentialCallee->removeFnAttr("amdgpu-no-lds-kernel-id");
10811080
}
1082-
1083-
continue;
10841081
}
1082+
} else {
1083+
Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
1084+
if (Visited.insert(Callee).second)
1085+
WorkList.push_back(Callee);
10851086
}
1086-
1087-
Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
1088-
if (Visited.insert(Callee).second)
1089-
Tmp.push_back(Callee);
10901087
}
1091-
} while (!Tmp.empty());
1088+
}
10921089
}
10931090

10941091
DenseMap<Function *, GlobalVariable *> lowerDynamicLDSVariables(

0 commit comments

Comments
 (0)