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
30 changes: 16 additions & 14 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6745,6 +6745,22 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
// value.
bool IsReference = D->getType()->isReferenceType();

// Function parameters.
// Note that it's important to check them first since we might have a local
// variable created for a ParmVarDecl as well.
if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
if (Ctx.getLangOpts().CPlusPlus && !Ctx.getLangOpts().CPlusPlus11 &&
!D->getType()->isIntegralOrEnumerationType()) {
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
/*InitializerFailed=*/false, E);
}
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);

return this->emitGetPtrParam(It->second.Offset, E);
}
}
// Local variables.
if (auto It = Locals.find(D); It != Locals.end()) {
const unsigned Offset = It->second.Offset;
Expand All @@ -6762,20 +6778,6 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {

return this->emitGetPtrGlobal(*GlobalIndex, E);
}
// Function parameters.
if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
if (Ctx.getLangOpts().CPlusPlus && !Ctx.getLangOpts().CPlusPlus11 &&
!D->getType()->isIntegralOrEnumerationType()) {
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
/*InitializerFailed=*/false, E);
}
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);

return this->emitGetPtrParam(It->second.Offset, E);
}
}

// In case we need to re-visit a declaration.
auto revisit = [&](const VarDecl *VD) -> bool {
Expand Down
19 changes: 19 additions & 0 deletions clang/test/AST/ByteCode/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,22 @@ namespace EnableIfWithTemporary {
struct A { ~A(); };
int &h() __attribute__((enable_if((A(), true), ""))); // both-warning {{clang extension}}
}

namespace LocalVarForParmVarDecl {
struct Iter {
void *p;
};
constexpr bool bar2(Iter A) {
return true;
}
constexpr bool bar(Iter A, bool b) {
if (b)
return true;

return bar(A, true);
}
constexpr int foo() {
return bar(Iter(), false);
}
static_assert(foo(), "");
}