llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/157328.diff 4 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+8-7) - (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+1-1) - (modified) clang/lib/AST/ByteCode/Program.cpp (+10-11) - (modified) clang/lib/AST/ByteCode/Program.h (+9-9) ``````````diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index d4e10b32c470c..c542b498ad22a 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2912,7 +2912,8 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr( OptPrimType SubExprT = classify(SubExpr); bool IsStatic = E->getStorageDuration() == SD_Static; if (IsStatic) { - std::optional<unsigned> GlobalIndex = P.createGlobal(E); + + UnsignedOrNone GlobalIndex = P.createGlobal(E); if (!GlobalIndex) return false; @@ -3009,7 +3010,7 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { if (T && !E->isLValue()) return this->delegate(Init); - std::optional<unsigned> GlobalIndex = P.createGlobal(E); + UnsignedOrNone GlobalIndex = P.createGlobal(E); if (!GlobalIndex) return false; @@ -3353,7 +3354,7 @@ bool Compiler<Emitter>::VisitSourceLocExpr(const SourceLocExpr *E) { auto *UGCD = cast<UnnamedGlobalConstantDecl>(BaseDecl); - std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(UGCD); + UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(UGCD); if (!GlobalIndex) return false; @@ -3876,7 +3877,7 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) { if (!RD->isCompleteDefinition()) return this->emitDummyPtr(GuidDecl, E); - std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(GuidDecl); + UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(GuidDecl); if (!GlobalIndex) return false; if (!this->emitGetPtrGlobal(*GlobalIndex, E)) @@ -4868,7 +4869,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, DeclScope<Emitter> LocalScope(this, VD); // We've already seen and initialized this global. - if (std::optional<unsigned> GlobalIndex = P.getGlobal(VD)) { + if (UnsignedOrNone GlobalIndex = P.getGlobal(VD)) { if (P.getPtrGlobal(*GlobalIndex).isInitialized()) return checkDecl(); @@ -4877,7 +4878,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, return Init && checkDecl() && initGlobal(*GlobalIndex); } - std::optional<unsigned> GlobalIndex = P.createGlobal(VD, Init); + UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init); if (!GlobalIndex) return false; @@ -6810,7 +6811,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { return F && this->emitGetFnPtr(F, E); } if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) { - if (std::optional<unsigned> Index = P.getOrCreateGlobal(D)) { + if (UnsignedOrNone Index = P.getOrCreateGlobal(D)) { if (!this->emitGetPtrGlobal(*Index, E)) return false; if (OptPrimType T = classify(E->getType())) { diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index f15cb5ffa63b0..d0aa8d8df2362 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -331,7 +331,7 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) { /// This is what we do here. void EvalEmitter::updateGlobalTemporaries() { for (const auto &[E, Temp] : S.SeenGlobalTemporaries) { - if (std::optional<unsigned> GlobalIndex = P.getGlobal(E)) { + if (UnsignedOrNone GlobalIndex = P.getGlobal(E)) { const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex); APValue *Cached = Temp->getOrCreateValue(true); diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 0be017ea59b91..75bfd9fd2d8ec 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -111,7 +111,7 @@ Pointer Program::getPtrGlobal(unsigned Idx) const { return Pointer(Globals[Idx]->block()); } -std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) { +UnsignedOrNone Program::getGlobal(const ValueDecl *VD) { if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end()) return It->second; @@ -131,14 +131,14 @@ std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) { return std::nullopt; } -std::optional<unsigned> Program::getGlobal(const Expr *E) { +UnsignedOrNone Program::getGlobal(const Expr *E) { if (auto It = GlobalIndices.find(E); It != GlobalIndices.end()) return It->second; return std::nullopt; } -std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD, - const Expr *Init) { +UnsignedOrNone Program::getOrCreateGlobal(const ValueDecl *VD, + const Expr *Init) { if (auto Idx = getGlobal(VD)) return Idx; @@ -195,8 +195,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) { return I; } -std::optional<unsigned> Program::createGlobal(const ValueDecl *VD, - const Expr *Init) { +UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) { bool IsStatic, IsExtern; bool IsWeak = VD->isWeak(); if (const auto *Var = dyn_cast<VarDecl>(VD)) { @@ -213,7 +212,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD, // Register all previous declarations as well. For extern blocks, just replace // the index with the new variable. - std::optional<unsigned> Idx = + UnsignedOrNone Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init); if (!Idx) return std::nullopt; @@ -240,7 +239,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD, return *Idx; } -std::optional<unsigned> Program::createGlobal(const Expr *E) { +UnsignedOrNone Program::createGlobal(const Expr *E) { if (auto Idx = getGlobal(E)) return Idx; if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true, @@ -251,9 +250,9 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) { return std::nullopt; } -std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty, - bool IsStatic, bool IsExtern, - bool IsWeak, const Expr *Init) { +UnsignedOrNone Program::createGlobal(const DeclTy &D, QualType Ty, + bool IsStatic, bool IsExtern, bool IsWeak, + const Expr *Init) { // Create a descriptor for the global. Descriptor *Desc; const bool IsConst = Ty.isConstQualified(); diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h index 90b48ee5b669b..28fcc97f5339d 100644 --- a/clang/lib/AST/ByteCode/Program.h +++ b/clang/lib/AST/ByteCode/Program.h @@ -78,21 +78,21 @@ class Program final { } /// Finds a global's index. - std::optional<unsigned> getGlobal(const ValueDecl *VD); - std::optional<unsigned> getGlobal(const Expr *E); + UnsignedOrNone getGlobal(const ValueDecl *VD); + UnsignedOrNone getGlobal(const Expr *E); /// Returns or creates a global an creates an index to it. - std::optional<unsigned> getOrCreateGlobal(const ValueDecl *VD, - const Expr *Init = nullptr); + UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, + const Expr *Init = nullptr); /// Returns or creates a dummy value for unknown declarations. unsigned getOrCreateDummy(const DeclTy &D); /// Creates a global and returns its index. - std::optional<unsigned> createGlobal(const ValueDecl *VD, const Expr *Init); + UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init); /// Creates a global from a lifetime-extended temporary. - std::optional<unsigned> createGlobal(const Expr *E); + UnsignedOrNone createGlobal(const Expr *E); /// Creates a new function from a code range. template <typename... Ts> @@ -165,9 +165,9 @@ class Program final { private: friend class DeclScope; - std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty, - bool IsStatic, bool IsExtern, - bool IsWeak, const Expr *Init = nullptr); + UnsignedOrNone createGlobal(const DeclTy &D, QualType Ty, bool IsStatic, + bool IsExtern, bool IsWeak, + const Expr *Init = nullptr); /// Reference to the VM context. Context &Ctx; `````````` </details> https://github.com/llvm/llvm-project/pull/157328 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits