Author: Timm Bäder Date: 2023-07-09T16:27:49+02:00 New Revision: 254ad7dd412308855ca29b97e9fd8079088cbef5
URL: https://github.com/llvm/llvm-project/commit/254ad7dd412308855ca29b97e9fd8079088cbef5 DIFF: https://github.com/llvm/llvm-project/commit/254ad7dd412308855ca29b97e9fd8079088cbef5.diff LOG: [clang][Interp][NFC] Move isGloballyIndexed() to Context And use it in Program as well, to make a similar decision. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h clang/lib/AST/Interp/Context.h clang/lib/AST/Interp/Program.cpp Removed: ################################################################################ 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<Emitter>::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<Emitter>::visitVarDecl(const VarDecl *VD) { 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 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<ByteCodeExprGen<Emitter>, 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<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 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<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 5adc4cf3b54748..1ebf9e8cbb1655 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -162,7 +162,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD, 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits