[llvm] Resolve static analyser report on pointer dereferencing after null check (PR #88278)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 12 06:19:23 PDT 2024


================
@@ -1052,43 +1052,39 @@ 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();
-              if (!isKernelLDS(PotentialCallee))
+            for (auto &ExternalCallRecord : *CG.getExternalCallingNode()) {
+              Function *PotentialCallee =
+                  ExternalCallRecord.second->getFunction();
+              if (PotentialCallee && !isKernelLDS(PotentialCallee))
----------------
arsenm wrote:

The externally calling function can't be null, it would have to be a known function in the call graph. Just make the null check an assert?

https://github.com/llvm/llvm-project/pull/88278


More information about the llvm-commits mailing list