diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-05-08 05:22:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-08 05:22:11 +0200 |
commit | dc28f9d087324f77db81e7192648a17ebf036125 (patch) | |
tree | d3e24af08c37a4c90a76306f45df51e988055ceb /clang | |
parent | eebb50afaf27961b21847950179febdd20a98866 (diff) | |
download | llvm-dc28f9d087324f77db81e7192648a17ebf036125.zip llvm-dc28f9d087324f77db81e7192648a17ebf036125.tar.gz llvm-dc28f9d087324f77db81e7192648a17ebf036125.tar.bz2 |
[clang][ExprConstant] Bail out on invalid lambda capture inits (#138832)
Fixes https://github.com/llvm/llvm-project/issues/138824
Diffstat (limited to 'clang')
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 2 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 5 | ||||
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 9 |
4 files changed, 14 insertions, 4 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4c25d6d..0d8c365 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -564,6 +564,8 @@ Bug Fixes in This Version the invalid attribute location appropriately. (#GH137861) - Fixed a crash when a malformed ``_Pragma`` directive appears as part of an ``#include`` directive. (#GH138094) +- Fixed a crash during constant evaluation involving invalid lambda captures + (#GH138832) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index ae6574c..3cc55c7 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2932,10 +2932,9 @@ bool Compiler<Emitter>::VisitLambdaExpr(const LambdaExpr *E) { // record with their initializers. for (const Record::Field &F : R->fields()) { const Expr *Init = *CaptureInitIt; - ++CaptureInitIt; - - if (!Init) + if (!Init || Init->containsErrors()) continue; + ++CaptureInitIt; if (std::optional<PrimType> T = classify(Init)) { if (!this->visit(Init)) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e5950f4..500d43a 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11038,7 +11038,7 @@ bool RecordExprEvaluator::VisitLambdaExpr(const LambdaExpr *E) { // If there is no initializer, either this is a VLA or an error has // occurred. - if (!CurFieldInit) + if (!CurFieldInit || CurFieldInit->containsErrors()) return Error(E); LValue Subobject = This; diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index dc8f4bf1..0a13565 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -2598,3 +2598,12 @@ void foo() { constexpr S s[2] = { }; // expected-error {{constexpr variable 's' must be initialized by a constant expression}} } } + +namespace DoubleCapture { + int DC() { + int a = 1000; + static auto f = + [a, &a] { // expected-error {{'a' can appear only once in a capture list}} + }; + } +} |