diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index a2cf682b2532b..15a7170896603 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2119,27 +2119,33 @@ bool ByteCodeExprGen::visitDecl(const VarDecl *VD) { if (!this->visitVarDecl(VD)) return false; + std::optional VarT = classify(VD->getType()); // Get a pointer to the variable if (Context::shouldBeGloballyIndexed(VD)) { auto GlobalIndex = P.getGlobal(VD); assert(GlobalIndex); // visitVarDecl() didn't return false. - if (!this->emitGetPtrGlobal(*GlobalIndex, VD)) - return false; + if (VarT) { + if (!this->emitGetGlobal(*VarT, *GlobalIndex, VD)) + return false; + } else { + if (!this->emitGetPtrGlobal(*GlobalIndex, VD)) + return false; + } } else { auto Local = Locals.find(VD); assert(Local != Locals.end()); // Same here. - if (!this->emitGetPtrLocal(Local->second.Offset, VD)) - return false; + if (VarT) { + if (!this->emitGetLocal(*VarT, Local->second.Offset, VD)) + return false; + } else { + if (!this->emitGetPtrLocal(Local->second.Offset, VD)) + return false; + } } // Return the value - if (std::optional VarT = classify(VD->getType())) { - if (!this->emitLoadPop(*VarT, VD)) - return false; - + if (VarT) return this->emitRet(*VarT, VD); - } - return this->emitRetValue(VD); }