Skip to content

Commit dc28f9d

Browse files
authored
[clang][ExprConstant] Bail out on invalid lambda capture inits (#138832)
Fixes #138824
1 parent eebb50a commit dc28f9d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ Bug Fixes in This Version
564564
the invalid attribute location appropriately. (#GH137861)
565565
- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an
566566
``#include`` directive. (#GH138094)
567+
- Fixed a crash during constant evaluation involving invalid lambda captures
568+
(#GH138832)
567569

568570
Bug Fixes to Compiler Builtins
569571
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,10 +2932,9 @@ bool Compiler<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
29322932
// record with their initializers.
29332933
for (const Record::Field &F : R->fields()) {
29342934
const Expr *Init = *CaptureInitIt;
2935-
++CaptureInitIt;
2936-
2937-
if (!Init)
2935+
if (!Init || Init->containsErrors())
29382936
continue;
2937+
++CaptureInitIt;
29392938

29402939
if (std::optional<PrimType> T = classify(Init)) {
29412940
if (!this->visit(Init))

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11038,7 +11038,7 @@ bool RecordExprEvaluator::VisitLambdaExpr(const LambdaExpr *E) {
1103811038

1103911039
// If there is no initializer, either this is a VLA or an error has
1104011040
// occurred.
11041-
if (!CurFieldInit)
11041+
if (!CurFieldInit || CurFieldInit->containsErrors())
1104211042
return Error(E);
1104311043

1104411044
LValue Subobject = This;

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,3 +2598,12 @@ void foo() {
25982598
constexpr S s[2] = { }; // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
25992599
}
26002600
}
2601+
2602+
namespace DoubleCapture {
2603+
int DC() {
2604+
int a = 1000;
2605+
static auto f =
2606+
[a, &a] { // expected-error {{'a' can appear only once in a capture list}}
2607+
};
2608+
}
2609+
}

0 commit comments

Comments
 (0)