Skip to content

[clang][analyzer] Do not analyze opaque types in CXXDeleteChecker #70638

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

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

Discookie
Copy link
Contributor

@Discookie Discookie commented Oct 30, 2023

While inheritance can only be expressed if the class has a definition, in this case one of the types might be opaque to the analyzer.

Fixes a crash encountered while analyzing LLVM.

While inheritance can only be expressed if the class has a definition, in this case one of the types might be opaque to the analyzer.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Oct 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Discookie (Discookie)

Changes

While inheritance can only be expressed if the class has a definition, in this case one of the types might be opaque to the analyzer.

Fixes a crash encountered whie analyzing LLVM.


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

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp (+6)
diff --git a/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
index 1a1f5c530294038..eb265f4dde68bc2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
@@ -114,6 +114,9 @@ void DeleteWithNonVirtualDtorChecker::checkTypedDeleteExpr(
   if (!BaseClass || !DerivedClass)
     return;
 
+  if (!BaseClass->hasDefinition() || !DerivedClass->hasDefinition())
+    return;
+
   if (BaseClass->getDestructor()->isVirtual())
     return;
 
@@ -148,6 +151,9 @@ void CXXArrayDeleteChecker::checkTypedDeleteExpr(
   if (!BaseClass || !DerivedClass)
     return;
 
+  if (!BaseClass->hasDefinition() || !DerivedClass->hasDefinition())
+    return;
+
   if (DE->getOperatorDelete()->getOverloadedOperator() != OO_Array_Delete)
     return;
 

@Discookie Discookie changed the title [clang][analyzer] Fix crash in CXXDeleteChecker [clang][analyzer] Do not analyze opaque types in CXXDeleteChecker Oct 30, 2023
Copy link
Contributor

@NagyDonat NagyDonat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, seems to be a straightforward fix.

Note that "whie" is a typo in the commit message.

@Discookie Discookie merged commit 564e016 into llvm:main Oct 30, 2023
@Xazax-hun
Copy link
Collaborator

In case it is not too hard to synthesize a test case, could you add a regression test as well in a follow-up commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants