llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> …rNone --- Full diff: https://github.com/llvm/llvm-project/pull/154286.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+32-33) - (modified) clang/lib/AST/ByteCode/Compiler.h (+7-7) ``````````diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index f2ce69a62838e..d5c7bdaeeb73a 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -256,7 +256,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // Prepare storage for the result. if (!Initializing && !SubExprT) { - std::optional<unsigned> LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -609,7 +609,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { // We're creating a complex value here, so we need to // allocate storage for it. if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateTemporary(CE); + UnsignedOrNone LocalIndex = allocateTemporary(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -633,7 +633,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isAnyComplexType()); assert(SubExpr->getType()->isAnyComplexType()); if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(CE); + UnsignedOrNone LocalIndex = allocateLocal(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -678,7 +678,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isVectorType()); if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(CE); + UnsignedOrNone LocalIndex = allocateLocal(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -722,7 +722,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isVectorType()); if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateTemporary(CE); + UnsignedOrNone LocalIndex = allocateTemporary(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -810,7 +810,7 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) { return true; if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -911,7 +911,7 @@ bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) { // We need a temporary variable holding our return value. if (!Initializing) { - std::optional<unsigned> ResultIndex = this->allocateLocal(BO); + UnsignedOrNone ResultIndex = this->allocateLocal(BO); if (!this->emitGetPtrLocal(*ResultIndex, BO)) return false; } @@ -1151,7 +1151,7 @@ template <class Emitter> bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) { // Prepare storage for result. if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -1210,7 +1210,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) { if (!LHSIsComplex) { // This is using the RHS type for the fake-complex LHS. - std::optional<unsigned> LocalIndex = allocateTemporary(RHS); + UnsignedOrNone LocalIndex = allocateTemporary(RHS); if (!LocalIndex) return false; LHSOffset = *LocalIndex; @@ -1385,7 +1385,7 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) { // Prepare storage for result. if (!Initializing && !E->isCompoundAssignmentOp()) { - std::optional<unsigned> LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -2090,7 +2090,7 @@ bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args, ExplicitMemberFn); } - std::optional<unsigned> LocalIndex = + UnsignedOrNone LocalIndex = allocateLocal(std::move(Source), Arg->getType(), /*ExtendingDecl=*/nullptr, ScopeKind::Call); if (!LocalIndex) @@ -2933,7 +2933,7 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr( return false; const Expr *Inner = E->getSubExpr()->skipRValueSubobjectAdjustments(); - if (std::optional<unsigned> LocalIndex = + if (UnsignedOrNone LocalIndex = allocateLocal(E, Inner->getType(), E->getExtendingDecl())) { InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalIndex)); if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -3010,7 +3010,7 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { unsigned LocalIndex; if (T) LocalIndex = this->allocateLocalPrimitive(Init, *T, /*IsConst=*/false); - else if (std::optional<unsigned> MaybeIndex = this->allocateLocal(Init)) + else if (UnsignedOrNone MaybeIndex = this->allocateLocal(Init)) LocalIndex = *MaybeIndex; else return false; @@ -3194,7 +3194,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) { if (Ctor->isTrivial()) return true; assert(!Initializing); - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; @@ -3397,7 +3397,7 @@ bool Compiler<Emitter>::VisitCXXScalarValueInitExpr( if (const auto *CT = Ty->getAs<ComplexType>()) { if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -3420,7 +3420,7 @@ bool Compiler<Emitter>::VisitCXXScalarValueInitExpr( if (const auto *VT = Ty->getAs<VectorType>()) { // FIXME: Code duplication with the _Complex case above. if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -4046,8 +4046,7 @@ bool Compiler<Emitter>::VisitExtVectorElementExpr( // Now the vector variable for the return value. if (!Initializing) { - std::optional<unsigned> ResultIndex; - ResultIndex = allocateLocal(E); + UnsignedOrNone ResultIndex = allocateLocal(E); if (!ResultIndex) return false; if (!this->emitGetPtrLocal(*ResultIndex, E)) @@ -4172,7 +4171,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) { // Create local variable to hold the return value. if (!E->isGLValue() && !E->getType()->isAnyComplexType() && !canClassify(E->getType())) { - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; @@ -4533,10 +4532,10 @@ unsigned Compiler<Emitter>::allocateLocalPrimitive( } template <class Emitter> -std::optional<unsigned> -Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty, - const ValueDecl *ExtendingDecl, ScopeKind SC, - bool IsConstexprUnknown) { +UnsignedOrNone Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty, + const ValueDecl *ExtendingDecl, + ScopeKind SC, + bool IsConstexprUnknown) { const ValueDecl *Key = nullptr; const Expr *Init = nullptr; bool IsTemporary = false; @@ -4570,7 +4569,7 @@ Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty, } template <class Emitter> -std::optional<unsigned> Compiler<Emitter>::allocateTemporary(const Expr *E) { +UnsignedOrNone Compiler<Emitter>::allocateTemporary(const Expr *E) { QualType Ty = E->getType(); assert(!Ty->isRecordType()); @@ -4649,7 +4648,7 @@ bool Compiler<Emitter>::visitExpr(const Expr *E, bool DestroyToplevelScope) { // Expressions with a composite return type. // For us, that means everything we don't // have a PrimType for. - if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) { + if (UnsignedOrNone LocalOffset = this->allocateLocal(E)) { InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalOffset)); if (!this->emitGetPtrLocal(*LocalOffset, E)) return false; @@ -4846,7 +4845,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, return this->emitSetLocal(*VarT, Offset, VD); } } else { - if (std::optional<unsigned> Offset = this->allocateLocal( + if (UnsignedOrNone Offset = this->allocateLocal( VD, VD->getType(), nullptr, ScopeKind::Block, IsConstexprUnknown)) { if (!Init) return true; @@ -4998,7 +4997,7 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E, // Non-primitive return type. Prepare storage. if (!Initializing && !ReturnT && !ReturnType->isVoidType()) { - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -5094,7 +5093,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) { // If we need to discard the return value but the function returns its // value via an RVO pointer, we need to create one such pointer just // for this call. - if (std::optional<unsigned> LocalIndex = allocateLocal(E)) { + if (UnsignedOrNone LocalIndex = allocateLocal(E)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -5102,7 +5101,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) { // We need the result. Prepare a pointer to return or // dup the current one. if (!Initializing) { - if (std::optional<unsigned> LocalIndex = allocateLocal(E)) { + if (UnsignedOrNone LocalIndex = allocateLocal(E)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -5138,7 +5137,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) { } bool Devirtualized = false; - std::optional<unsigned> CalleeOffset; + UnsignedOrNone CalleeOffset = std::nullopt; // Add the (optional, implicit) This pointer. if (const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) { if (!FuncDecl && classifyPrim(E->getCallee()) == PT_MemberPtr) { @@ -6546,7 +6545,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) { OptPrimType ResT = classify(E); auto prepareResult = [=]() -> bool { if (!ResT && !Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; return this->emitGetPtrLocal(*LocalIndex, E); @@ -6664,7 +6663,7 @@ bool Compiler<Emitter>::VisitVectorUnaryOperator(const UnaryOperator *E) { return this->delegate(SubExpr); if (!Initializing) { - std::optional<unsigned> LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -7268,7 +7267,7 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) { // Prepare storage for the result in case we discard. if (DiscardResult && !Initializing && !ToT) { - std::optional<unsigned> LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index 20571df0432f9..90c4caca1874f 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -316,11 +316,11 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>, bool IsConstexprUnknown = false); /// Allocates a space storing a local given its type. - std::optional<unsigned> - allocateLocal(DeclTy &&Decl, QualType Ty = QualType(), - const ValueDecl *ExtendingDecl = nullptr, - ScopeKind = ScopeKind::Block, bool IsConstexprUnknown = false); - std::optional<unsigned> allocateTemporary(const Expr *E); + UnsignedOrNone allocateLocal(DeclTy &&Decl, QualType Ty = QualType(), + const ValueDecl *ExtendingDecl = nullptr, + ScopeKind = ScopeKind::Block, + bool IsConstexprUnknown = false); + UnsignedOrNone allocateTemporary(const Expr *E); private: friend class VariableScope<Emitter>; @@ -567,7 +567,7 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> { void addLocal(const Scope::Local &Local) override { if (!Idx) { - Idx = this->Ctx->Descriptors.size(); + Idx = static_cast<unsigned>(this->Ctx->Descriptors.size()); this->Ctx->Descriptors.emplace_back(); this->Ctx->emitInitScope(*Idx, {}); } @@ -615,7 +615,7 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> { } /// Index of the scope in the chain. - std::optional<unsigned> Idx; + UnsignedOrNone Idx = std::nullopt; }; /// Scope for storage declared in a compound statement. `````````` </details> https://github.com/llvm/llvm-project/pull/154286 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits