https://github.com/macurtis-amd created 
https://github.com/llvm/llvm-project/pull/170180

See similar PR #169593.

This is another case where null was not be handled when returned from 
`getDestructorDecl`.

>From 1128ebce5f004f0320c440cef3d4b848dc50aadb Mon Sep 17 00:00:00 2001
From: Matthew Curtis <[email protected]>
Date: Mon, 1 Dec 2025 12:29:39 -0600
Subject: [PATCH] [clang] Handle null dtor decl during consumed analysis

---
 clang/lib/Analysis/Consumed.cpp                  | 9 +++++----
 clang/test/SemaCXX/no-warn-consumed-analysis.cpp | 9 +++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/no-warn-consumed-analysis.cpp

diff --git a/clang/lib/Analysis/Consumed.cpp b/clang/lib/Analysis/Consumed.cpp
index f2c714ab1528d..efc7098e52042 100644
--- a/clang/lib/Analysis/Consumed.cpp
+++ b/clang/lib/Analysis/Consumed.cpp
@@ -1354,12 +1354,13 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) {
 
       case CFGElement::AutomaticObjectDtor: {
         const CFGAutomaticObjDtor &DTor = B.castAs<CFGAutomaticObjDtor>();
+        const auto *DD = DTor.getDestructorDecl(AC.getASTContext());
+        if (!DD)
+          break;
+
         SourceLocation Loc = DTor.getTriggerStmt()->getEndLoc();
         const VarDecl *Var = DTor.getVarDecl();
-
-        Visitor.checkCallability(PropagationInfo(Var),
-                                 DTor.getDestructorDecl(AC.getASTContext()),
-                                 Loc);
+        Visitor.checkCallability(PropagationInfo(Var), DD, Loc);
         break;
       }
 
diff --git a/clang/test/SemaCXX/no-warn-consumed-analysis.cpp 
b/clang/test/SemaCXX/no-warn-consumed-analysis.cpp
new file mode 100644
index 0000000000000..59d503661a0b1
--- /dev/null
+++ b/clang/test/SemaCXX/no-warn-consumed-analysis.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -fcxx-exceptions 
-std=c++11 %s
+// expected-no-diagnostics
+
+struct foo {
+  ~foo();
+};
+struct bar : foo {};
+struct baz : bar {};
+baz foobar(baz a) { return a; }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to