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
32 changes: 20 additions & 12 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6532,14 +6532,13 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
if (DiscardResult)
return true;

if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
if (const auto *ECD = dyn_cast<EnumConstantDecl>(D))
return this->emitConst(ECD->getInitVal(), E);
} else if (const auto *BD = dyn_cast<BindingDecl>(D)) {
return this->visit(BD->getBinding());
} else if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
const Function *F = getFunction(FuncDecl);
return F && this->emitGetFnPtr(F, E);
} else if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
}
if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
if (std::optional<unsigned> Index = P.getOrCreateGlobal(D)) {
if (!this->emitGetPtrGlobal(*Index, E))
return false;
Expand All @@ -6560,21 +6559,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
// value.
bool IsReference = D->getType()->isReferenceType();

// Check for local/global variables and parameters.
// Local variables.
if (auto It = Locals.find(D); It != Locals.end()) {
const unsigned Offset = It->second.Offset;
if (IsReference)
return this->emitGetLocal(classifyPrim(E), Offset, E);
return this->emitGetPtrLocal(Offset, E);
} else if (auto GlobalIndex = P.getGlobal(D)) {
}
// Global variables.
if (auto GlobalIndex = P.getGlobal(D)) {
if (IsReference) {
if (!Ctx.getLangOpts().CPlusPlus11)
return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E);
return this->emitGetGlobalUnchecked(classifyPrim(E), *GlobalIndex, E);
}

return this->emitGetPtrGlobal(*GlobalIndex, E);
} else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
}
// Function parameters.
if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
if (auto It = this->Params.find(PVD); It != this->Params.end()) {
if (IsReference || !It->second.IsPtr)
return this->emitGetParam(classifyPrim(E), It->second.Offset, E);
Expand All @@ -6600,20 +6603,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
return this->visitDeclRef(D, E);
};

// Handle lambda captures.
// Lambda captures.
if (auto It = this->LambdaCaptures.find(D);
It != this->LambdaCaptures.end()) {
auto [Offset, IsPtr] = It->second;

if (IsPtr)
return this->emitGetThisFieldPtr(Offset, E);
return this->emitGetPtrThisField(Offset, E);
} else if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
DRE && DRE->refersToEnclosingVariableOrCapture()) {
}

if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
DRE && DRE->refersToEnclosingVariableOrCapture()) {
if (const auto *VD = dyn_cast<VarDecl>(D); VD && VD->isInitCapture())
return revisit(VD);
}

if (const auto *BD = dyn_cast<BindingDecl>(D))
return this->visit(BD->getBinding());

// Avoid infinite recursion.
if (D == InitializingDecl)
return this->emitDummyPtr(D, E);
Expand Down Expand Up @@ -6666,7 +6674,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
if (VD->evaluateValue())
return revisit(VD);

if (!D->getType()->isReferenceType())
if (!IsReference)
return this->emitDummyPtr(D, E);

return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
Expand Down
4 changes: 4 additions & 0 deletions clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -fcxx-exceptions
// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER -fcxx-exceptions

// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s -fcxx-exceptions -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -fblocks %s -fcxx-exceptions -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -fcxx-exceptions -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER -fcxx-exceptions -fexperimental-new-constant-interpreter

namespace test_lambda_is_literal {
#ifdef CPP14_AND_EARLIER
Expand Down
Loading