diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 0afd772c73b85..3e1f36da8925f 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -307,7 +307,7 @@ bool isConstexprUnknown(const Pointer &P) { if (P.isDummy()) return false; const VarDecl *VD = P.block()->getDescriptor()->asVarDecl(); - return VD && VD->hasLocalStorage(); + return VD && VD->hasLocalStorage() && !isa(VD); } bool CheckBCPResult(InterpState &S, const Pointer &Ptr) { diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 4e84dcc8d551d..b4e15b3ffbe68 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -771,6 +771,11 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr, bool CanOverflow) { assert(!Ptr.isDummy()); + if (!S.inConstantContext()) { + if (isConstexprUnknown(Ptr)) + return false; + } + if constexpr (std::is_same_v) { if (!S.getLangOpts().CPlusPlus14) return Invalid(S, OpPC); diff --git a/clang/test/AST/ByteCode/codegen.cpp b/clang/test/AST/ByteCode/codegen.cpp index ea2c812f30f6f..7c853a20362b8 100644 --- a/clang/test/AST/ByteCode/codegen.cpp +++ b/clang/test/AST/ByteCode/codegen.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s #ifdef __SIZEOF_INT128__ @@ -95,3 +95,12 @@ void f(A *a) { // CHECK: call void @_ZN1AD1Ev( A::E e3 = A().Foo; } + +int notdead() { + auto l = [c=0]() mutable { + return c++ < 5 ? 10 : 12; + }; + return l(); +} +// CHECK: _ZZ7notdeadvEN3$_0clEv +// CHECK: ret i32 %cond