https://github.com/Hao-Chen2337 updated 
https://github.com/llvm/llvm-project/pull/215724

>From 92d5c5a0032614a66965f73dd4f2816f3198a652 Mon Sep 17 00:00:00 2001
From: Hao-Chen2337 <[email protected]>
Date: Wed, 12 Aug 2026 11:13:14 +0800
Subject: [PATCH 1/2] [clang-tidy] Fix crash on pointer arithmetic with an
 incomplete type in bugprone-pointer-arithmetic-on-polymorphic-object

---
 .../PointerArithmeticOnPolymorphicObjectCheck.cpp      |  8 ++++++--
 .../pointer-arithmetic-on-polymorphic-object-all.cpp   | 10 ++++++++++
 ...nter-arithmetic-on-polymorphic-object-decl-only.cpp | 10 ++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp
 
b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp
index ef5fee9f3d2c3..e54a77953283a 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/PointerArithmeticOnPolymorphicObjectCheck.cpp
@@ -15,8 +15,12 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::bugprone {
 
 namespace {
-AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
-AST_MATCHER(CXXRecordDecl, isPolymorphic) { return Node.isPolymorphic(); }
+AST_MATCHER(CXXRecordDecl, isAbstract) {
+  return Node.hasDefinition() && Node.isAbstract();
+}
+AST_MATCHER(CXXRecordDecl, isPolymorphic) {
+  return Node.hasDefinition() && Node.isPolymorphic();
+}
 } // namespace
 
 PointerArithmeticOnPolymorphicObjectCheck::
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp
index f8163a2fd3fb8..80be193a41535 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-all.cpp
@@ -150,3 +150,13 @@ struct TemplateHolder : Base {
     (void)x;
   }
 };
+
+// pointer arithmetic on an incomplete type must not crash the matcher.
+template <typename T>
+struct IncompletePointeeCrash {
+  struct Incomplete;
+  void f(Incomplete *p) {
+    p[0];
+    // no-warning
+  }
+};
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-decl-only.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-decl-only.cpp
index 48757bbc9b10e..f8a741cb5b174 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-decl-only.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/pointer-arithmetic-on-polymorphic-object-decl-only.cpp
@@ -139,3 +139,13 @@ void typeAliases(BaseAlias *b, DerivedAlias *d, 
FinalDerivedAlias *fd,
   fdp += 1;
   // no-warning
 }
+
+// pointer arithmetic on an incomplete type must not crash the matcher.
+template <typename T>
+struct IncompletePointeeCrash {
+  struct Incomplete;
+  void f(Incomplete *p) {
+    p[0];
+    // no-warning
+  }
+};

>From 92b6fdae9baca4825ef79eddd9faf799cb60f2b9 Mon Sep 17 00:00:00 2001
From: Hao-Chen2337 <[email protected]>
Date: Wed, 12 Aug 2026 14:12:18 +0800
Subject: [PATCH 2/2] [clang-tidy] Add release note for crash fix in
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 clang-tools-extra/docs/ReleaseNotes.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.md 
b/clang-tools-extra/docs/ReleaseNotes.md
index 29de9aef9e4b6..d418d21d1c252 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -118,6 +118,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   <clang-tidy/checks/bugprone/std-namespace-modification>` when checking
   lambda closure types used as template arguments.
 
+- Fixed a crash in {doc}`bugprone-pointer-arithmetic-on-polymorphic-object
+  <clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object>` when
+  the pointer points to an incomplete (forward-declared) type.
+
 - Improved {doc}`cppcoreguidelines-pro-type-member-init
   <clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check by treating
   `std::array` the same as built-in arrays when `IgnoreArrays` option is 
enabled.

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

Reply via email to