Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][Clang] Fix static analyzer concern #88179

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

elizabethandrews
Copy link
Contributor

Fix static analyzer concerns about dereferencing
null values.

Fix static analyzer concerns about dereferencing
null values.
@elizabethandrews elizabethandrews marked this pull request as ready for review April 9, 2024 19:57
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 9, 2024

@llvm/pr-subscribers-clang

Author: None (elizabethandrews)

Changes

Fix static analyzer concerns about dereferencing
null values.


Full diff: https://github.com/llvm/llvm-project/pull/88179.diff

2 Files Affected:

  • (modified) clang/lib/AST/Interp/InterpState.h (+5-1)
  • (modified) clang/lib/Sema/SemaAPINotes.cpp (+2)
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..abcf5132578eb4 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);

@elizabethandrews
Copy link
Contributor Author

Thanks for the review!

@elizabethandrews elizabethandrews merged commit b074f25 into llvm:main Apr 12, 2024
8 checks passed
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Fix static analyzer concerns about dereferencing
null values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants