Skip to content

Commit d0eeb21

Browse files
mmoadelichangpeng
authored andcommitted
Resolve static analyser report on pointer dereferencing after null check (llvm#88278)
- Resolve Static Analyzer Check Failure: Pointer Dereferencing After Null Check. - Minor naming and style improvement Change-Id: I970ef318ffbde90c779c3e9b1336f3cd76cd5c4d
1 parent 1c634b5 commit d0eeb21

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
@@ -1034,43 +1034,40 @@ class AMDGPULowerModuleLDS {
10341034
void removeNoLdsKernelIdFromReachable(CallGraph &CG, Function *KernelRoot) {
10351035
KernelRoot->removeFnAttr("amdgpu-no-lds-kernel-id");
10361036

1037-
SmallVector<Function *> Tmp({CG[KernelRoot]->getFunction()});
1038-
if (!Tmp.back())
1039-
return;
1040-
1037+
SmallVector<Function *> WorkList({CG[KernelRoot]->getFunction()});
10411038
SmallPtrSet<Function *, 8> Visited;
10421039
bool SeenUnknownCall = false;
10431040

1044-
do {
1045-
Function *F = Tmp.pop_back_val();
1041+
while (!WorkList.empty()) {
1042+
Function *F = WorkList.pop_back_val();
10461043

1047-
for (auto &N : *CG[F]) {
1048-
if (!N.second)
1044+
for (auto &CallRecord : *CG[F]) {
1045+
if (!CallRecord.second)
10491046
continue;
10501047

1051-
Function *Callee = N.second->getFunction();
1048+
Function *Callee = CallRecord.second->getFunction();
10521049
if (!Callee) {
10531050
if (!SeenUnknownCall) {
10541051
SeenUnknownCall = true;
10551052

10561053
// If we see any indirect calls, assume nothing about potential
10571054
// targets.
10581055
// TODO: This could be refined to possible LDS global users.
1059-
for (auto &N : *CG.getExternalCallingNode()) {
1060-
Function *PotentialCallee = N.second->getFunction();
1056+
for (auto &ExternalCallRecord : *CG.getExternalCallingNode()) {
1057+
Function *PotentialCallee =
1058+
ExternalCallRecord.second->getFunction();
1059+
assert(PotentialCallee);
10611060
if (!isKernelLDS(PotentialCallee))
10621061
PotentialCallee->removeFnAttr("amdgpu-no-lds-kernel-id");
10631062
}
1064-
1065-
continue;
10661063
}
1064+
} else {
1065+
Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
1066+
if (Visited.insert(Callee).second)
1067+
WorkList.push_back(Callee);
10671068
}
1068-
1069-
Callee->removeFnAttr("amdgpu-no-lds-kernel-id");
1070-
if (Visited.insert(Callee).second)
1071-
Tmp.push_back(Callee);
10721069
}
1073-
} while (!Tmp.empty());
1070+
}
10741071
}
10751072

10761073
DenseMap<Function *, GlobalVariable *> lowerDynamicLDSVariables(

0 commit comments

Comments
 (0)