diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 86200f9ad08313..4f61f87b0fd241 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1617,7 +1617,7 @@ bool ByteCodeExprGen::visitDecl(const VarDecl *VD) { return false; // Get a pointer to the variable - if (shouldBeGloballyIndexed(VD)) { + if (Context::shouldBeGloballyIndexed(VD)) { auto GlobalIndex = P.getGlobal(VD); assert(GlobalIndex); // visitVarDecl() didn't return false. if (!this->emitGetPtrGlobal(*GlobalIndex, VD)) @@ -1649,7 +1649,7 @@ bool ByteCodeExprGen::visitVarDecl(const VarDecl *VD) { const Expr *Init = VD->getInit(); std::optional VarT = classify(VD->getType()); - if (shouldBeGloballyIndexed(VD)) { + if (Context::shouldBeGloballyIndexed(VD)) { // We've already seen and initialized this global. if (P.getGlobal(VD)) return true; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 83bafeb9aac616..57b0af9459e3ab 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -247,15 +247,6 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, return T->getAsCXXRecordDecl(); } - /// Returns whether we should create a global variable for the - /// given ValueDecl. - bool shouldBeGloballyIndexed(const ValueDecl *VD) const { - if (const auto *V = dyn_cast(VD)) - return V->hasGlobalStorage() || V->isConstexpr(); - - return false; - } - llvm::RoundingMode getRoundingMode(const Expr *E) const { FPOptions FPO = E->getFPFeaturesInEffect(Ctx.getLangOpts()); diff --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h index 8879186f7072ec..19d480d912116b 100644 --- a/clang/lib/AST/Interp/Context.h +++ b/clang/lib/AST/Interp/Context.h @@ -67,6 +67,14 @@ class Context final { getOverridingFunction(const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const; + /// Returns whether we should create a global variable for the + /// given ValueDecl. + static bool shouldBeGloballyIndexed(const ValueDecl *VD) { + if (const auto *V = dyn_cast(VD)) + return V->hasGlobalStorage() || V->isConstexpr(); + + return false; + } private: /// Runs a function. diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp index 5adc4cf3b54748..1ebf9e8cbb1655 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -162,7 +162,7 @@ std::optional Program::createGlobal(const ValueDecl *VD, assert(!getGlobal(VD)); bool IsStatic, IsExtern; if (auto *Var = dyn_cast(VD)) { - IsStatic = !Var->hasLocalStorage(); + IsStatic = Context::shouldBeGloballyIndexed(VD); IsExtern = !Var->getAnyInitializer(); } else { IsStatic = false;