[clang] [analyzer] Fix crash in PaddingChecker on dependent field types (PR #232986)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 16 16:58:08 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Manuel Sainz de Baranda y Goñi (redcode)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/232986.diff
2 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp (+6)
- (added) clang/test/Analysis/padding_dependent.cpp (+7)
``````````diff
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] {})) {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/232986
More information about the cfe-commits
mailing list