[clang][Interp][NFC] Move isGloballyIndexed() to Context
And use it in Program as well, to make a similar decision.
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 86200f9..4f61f87 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1617,7 +1617,7 @@
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 @@
const Expr *Init = VD->getInit();
std::optional<PrimType> 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 83bafeb..57b0af9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -247,15 +247,6 @@
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<VarDecl>(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 8879186..19d480d 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -67,6 +67,14 @@
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<VarDecl>(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 5adc4cf..1ebf9e8 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -162,7 +162,7 @@
assert(!getGlobal(VD));
bool IsStatic, IsExtern;
if (auto *Var = dyn_cast<VarDecl>(VD)) {
- IsStatic = !Var->hasLocalStorage();
+ IsStatic = Context::shouldBeGloballyIndexed(VD);
IsExtern = !Var->getAnyInitializer();
} else {
IsStatic = false;