@@ -6532,14 +6532,13 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6532
6532
if (DiscardResult)
6533
6533
return true ;
6534
6534
6535
- if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
6535
+ if (const auto *ECD = dyn_cast<EnumConstantDecl>(D))
6536
6536
return this ->emitConst (ECD->getInitVal (), E);
6537
- } else if (const auto *BD = dyn_cast<BindingDecl>(D)) {
6538
- return this ->visit (BD->getBinding ());
6539
- } else if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
6537
+ if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
6540
6538
const Function *F = getFunction (FuncDecl);
6541
6539
return F && this ->emitGetFnPtr (F, E);
6542
- } else if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6540
+ }
6541
+ if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6543
6542
if (std::optional<unsigned > Index = P.getOrCreateGlobal (D)) {
6544
6543
if (!this ->emitGetPtrGlobal (*Index, E))
6545
6544
return false ;
@@ -6560,21 +6559,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6560
6559
// value.
6561
6560
bool IsReference = D->getType ()->isReferenceType ();
6562
6561
6563
- // Check for local/global variables and parameters .
6562
+ // Local variables.
6564
6563
if (auto It = Locals.find (D); It != Locals.end ()) {
6565
6564
const unsigned Offset = It->second .Offset ;
6566
6565
if (IsReference)
6567
6566
return this ->emitGetLocal (classifyPrim (E), Offset, E);
6568
6567
return this ->emitGetPtrLocal (Offset, E);
6569
- } else if (auto GlobalIndex = P.getGlobal (D)) {
6568
+ }
6569
+ // Global variables.
6570
+ if (auto GlobalIndex = P.getGlobal (D)) {
6570
6571
if (IsReference) {
6571
6572
if (!Ctx.getLangOpts ().CPlusPlus11 )
6572
6573
return this ->emitGetGlobal (classifyPrim (E), *GlobalIndex, E);
6573
6574
return this ->emitGetGlobalUnchecked (classifyPrim (E), *GlobalIndex, E);
6574
6575
}
6575
6576
6576
6577
return this ->emitGetPtrGlobal (*GlobalIndex, E);
6577
- } else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6578
+ }
6579
+ // Function parameters.
6580
+ if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6578
6581
if (auto It = this ->Params .find (PVD); It != this ->Params .end ()) {
6579
6582
if (IsReference || !It->second .IsPtr )
6580
6583
return this ->emitGetParam (classifyPrim (E), It->second .Offset , E);
@@ -6600,20 +6603,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6600
6603
return this ->visitDeclRef (D, E);
6601
6604
};
6602
6605
6603
- // Handle lambda captures.
6606
+ // Lambda captures.
6604
6607
if (auto It = this ->LambdaCaptures .find (D);
6605
6608
It != this ->LambdaCaptures .end ()) {
6606
6609
auto [Offset, IsPtr] = It->second ;
6607
6610
6608
6611
if (IsPtr)
6609
6612
return this ->emitGetThisFieldPtr (Offset, E);
6610
6613
return this ->emitGetPtrThisField (Offset, E);
6611
- } else if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
6612
- DRE && DRE->refersToEnclosingVariableOrCapture ()) {
6614
+ }
6615
+
6616
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
6617
+ DRE && DRE->refersToEnclosingVariableOrCapture ()) {
6613
6618
if (const auto *VD = dyn_cast<VarDecl>(D); VD && VD->isInitCapture ())
6614
6619
return revisit (VD);
6615
6620
}
6616
6621
6622
+ if (const auto *BD = dyn_cast<BindingDecl>(D))
6623
+ return this ->visit (BD->getBinding ());
6624
+
6617
6625
// Avoid infinite recursion.
6618
6626
if (D == InitializingDecl)
6619
6627
return this ->emitDummyPtr (D, E);
@@ -6666,7 +6674,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6666
6674
if (VD->evaluateValue ())
6667
6675
return revisit (VD);
6668
6676
6669
- if (!D-> getType ()-> isReferenceType () )
6677
+ if (!IsReference )
6670
6678
return this ->emitDummyPtr (D, E);
6671
6679
6672
6680
return this ->emitInvalidDeclRef (cast<DeclRefExpr>(E),
0 commit comments