[clang] [NFC][Clang] Fix static analyzer concern (PR #88179)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 12:01:43 PDT 2024


https://github.com/elizabethandrews created https://github.com/llvm/llvm-project/pull/88179

Fix static analyzer concerns about dereferencing
null values.

>From b5eef2f7be6a109b490090b3854f40e0d5e415a2 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews <elizabeth.andrews at intel.com>
Date: Tue, 9 Apr 2024 11:45:38 -0700
Subject: [PATCH] [NFC][Clang] Fix static analyzer concern

Fix static analyzer concerns about dereferencing
null values.
---
 clang/lib/AST/Interp/InterpState.h | 6 +++++-
 clang/lib/Sema/SemaAPINotes.cpp    | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/InterpState.h b/clang/lib/AST/Interp/InterpState.h
index 8f84bf6ed2eaff..c17cfad11b1e2b 100644
--- a/clang/lib/AST/Interp/InterpState.h
+++ b/clang/lib/AST/Interp/InterpState.h
@@ -89,7 +89,11 @@ class InterpState final : public State, public SourceMapper {
 
   /// Delegates source mapping to the mapper.
   SourceInfo getSource(const Function *F, CodePtr PC) const override {
-    return M ? M->getSource(F, PC) : F->getSource(PC);
+    if (M)
+      return M->getSource(F, PC);
+
+    assert(F && "Function cannot be null");
+    return F->getSource(PC);
   }
 
   Context &getContext() const { return Ctx; }
diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp
index 836c633e9d2042..5c7d5d57dbbbbf 100644
--- a/clang/lib/Sema/SemaAPINotes.cpp
+++ b/clang/lib/Sema/SemaAPINotes.cpp
@@ -458,6 +458,8 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod AnyFunc,
     D = MD;
   }
 
+  assert((FD || MD) && “Expecting Function or ObjCMethod”);
+
   // Nullability of return type.
   if (Info.NullabilityAudited)
     applyNullability(S, D, Info.getReturnTypeInfo(), Metadata);



More information about the cfe-commits mailing list