diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 81da16e797bce..759d5a64f97be 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4574,22 +4574,23 @@ VarCreationState Compiler::visitDecl(const VarDecl *VD, template bool Compiler::visitDeclAndReturn(const VarDecl *VD, bool ConstantContext) { - std::optional VarT = classify(VD->getType()); // We only create variables if we're evaluating in a constant context. // Otherwise, just evaluate the initializer and return it. if (!ConstantContext) { DeclScope LS(this, VD); - if (!this->visit(VD->getAnyInitializer())) + const Expr *Init = VD->getInit(); + if (!this->visit(Init)) return false; - return this->emitRet(VarT.value_or(PT_Ptr), VD) && LS.destroyLocals() && - this->emitCheckAllocations(VD); + return this->emitRet(classify(Init).value_or(PT_Ptr), VD) && + LS.destroyLocals() && this->emitCheckAllocations(VD); } LocalScope VDScope(this, VD); if (!this->visitVarDecl(VD, /*Toplevel=*/true)) return false; + std::optional VarT = classify(VD->getType()); if (Context::shouldBeGloballyIndexed(VD)) { auto GlobalIndex = P.getGlobal(VD); assert(GlobalIndex); // visitVarDecl() didn't return false.