[clang] [clang][OpenMP][NFC] Remove unnecessary nullptr check (PR #94680)

Mike Rice via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 6 13:40:18 PDT 2024


https://github.com/mikerice1969 created https://github.com/llvm/llvm-project/pull/94680

Static verifier reports unchecked use of pointer after explicitly checking earlier in the function. It appears the pointer won't be a nullptr, so remove the unneeded check for consistency.

>From 476c5a8580c066cce91def36f8e8ed20626d3ab0 Mon Sep 17 00:00:00 2001
From: Mike Rice <michael.p.rice at intel.com>
Date: Thu, 6 Jun 2024 11:56:04 -0700
Subject: [PATCH] [OpenMP][NFC] Remove unnecessary nullptr check

Static verifier reports unchecked use of pointer after explicitly
checking earlier in the function. It appears the pointer won't be a
nullptr, so remove the unneeded check for consistency.
---
 clang/lib/Sema/SemaOpenMP.cpp | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e6815328e913..5af32cb3589d3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6198,18 +6198,17 @@ class TeamsLoopChecker final : public ConstStmtVisitor<TeamsLoopChecker> {
     // unless the assume-no-nested-parallelism flag has been specified.
     // OpenMP API runtime library calls do not inhibit parallel loop
     // translation, regardless of the assume-no-nested-parallelism.
-    if (C) {
-      bool IsOpenMPAPI = false;
-      auto *FD = dyn_cast_or_null<FunctionDecl>(C->getCalleeDecl());
-      if (FD) {
-        std::string Name = FD->getNameInfo().getAsString();
-        IsOpenMPAPI = Name.find("omp_") == 0;
-      }
-      TeamsLoopCanBeParallelFor =
-          IsOpenMPAPI || SemaRef.getLangOpts().OpenMPNoNestedParallelism;
-      if (!TeamsLoopCanBeParallelFor)
-        return;
-    }
+    bool IsOpenMPAPI = false;
+    auto *FD = dyn_cast_or_null<FunctionDecl>(C->getCalleeDecl());
+    if (FD) {
+      std::string Name = FD->getNameInfo().getAsString();
+      IsOpenMPAPI = Name.find("omp_") == 0;
+    }
+    TeamsLoopCanBeParallelFor =
+        IsOpenMPAPI || SemaRef.getLangOpts().OpenMPNoNestedParallelism;
+    if (!TeamsLoopCanBeParallelFor)
+      return;
+
     for (const Stmt *Child : C->children())
       if (Child)
         Visit(Child);



More information about the cfe-commits mailing list