[clang] [analyzer] Fix crash in PaddingChecker on dependent field types (PR #232986)
Manuel Sainz de Baranda y Goñi via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 16 16:57:30 PDT 2026
https://github.com/redcode created https://github.com/llvm/llvm-project/pull/232986
Fixes #232874
`PaddingChecker` also visits the implicit closure type of lambda expressions. A lambda with a dependent init-capture inside a `noexcept` specifier of an abbreviated function template is not marked as dependent, so the checker attempted to compute its record layout and crashed in `ASTContext::getTypeInfoImpl` on the dependent field type.
The fix skips records whose fields have dependent types, since their layout cannot be computed.
>From cf6bc51b6c05b752d249c32ceb6a066fa6daffad Mon Sep 17 00:00:00 2001
From: redcode <manuel at zxe.io>
Date: Sat, 17 Oct 2026 01:50:04 +0200
Subject: [PATCH] [analyzer] Fix crash in PaddingChecker on dependent field
types
---
clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp | 6 ++++++
clang/test/Analysis/padding_dependent.cpp | 7 +++++++
2 files changed, 13 insertions(+)
create mode 100644 clang/test/Analysis/padding_dependent.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
index c8d7b6555f3f4..8fbd1831f9175 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
@@ -178,6 +178,12 @@ class PaddingChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
QualType Ty = FD->getType();
if (Ty->isIncompleteArrayType())
return true;
+ // Dependent field types have no known layout, so we can't compute the
+ // padding of the enclosing record. This can happen for lambda captures
+ // in a dependent context, e.g. an init-capture of a forwarding reference
+ // inside a noexcept specifier.
+ if (Ty->isDependentType())
+ return true;
return false;
};
diff --git a/clang/test/Analysis/padding_dependent.cpp b/clang/test/Analysis/padding_dependent.cpp
new file mode 100644
index 0000000000000..ea337d1337950
--- /dev/null
+++ b/clang/test/Analysis/padding_dependent.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=optin.performance -verify %s
+
+// The static analyzer must not crash when computing the layout of a lambda
+// closure type with a dependent init-capture inside a noexcept specifier.
+// https://github.com/llvm/llvm-project/issues/232874
+// expected-no-diagnostics
+void crasher(auto&& fn) noexcept(noexcept([_ = fn] {})) {}
More information about the cfe-commits
mailing list