Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParmVarDecl>(VD);
}

bool CheckBCPResult(InterpState &S, const Pointer &Ptr) {
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, Boolean>) {
if (!S.getLangOpts().CPlusPlus14)
return Invalid(S, OpPC);
Expand Down
11 changes: 10 additions & 1 deletion clang/test/AST/ByteCode/codegen.cpp
Original file line number Diff line number Diff line change
@@ -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__
Expand Down Expand Up @@ -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