diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index e9d937fa632c..e3235d34e230 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -256,7 +256,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { // Prepare storage for the result. if (!Initializing && !SubExprT) { - std::optional LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -609,7 +609,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { // We're creating a complex value here, so we need to // allocate storage for it. if (!Initializing) { - std::optional LocalIndex = allocateTemporary(CE); + UnsignedOrNone LocalIndex = allocateTemporary(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -633,7 +633,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isAnyComplexType()); assert(SubExpr->getType()->isAnyComplexType()); if (!Initializing) { - std::optional LocalIndex = allocateLocal(CE); + UnsignedOrNone LocalIndex = allocateLocal(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -678,7 +678,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isVectorType()); if (!Initializing) { - std::optional LocalIndex = allocateLocal(CE); + UnsignedOrNone LocalIndex = allocateLocal(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -722,7 +722,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { assert(CE->getType()->isVectorType()); if (!Initializing) { - std::optional LocalIndex = allocateTemporary(CE); + UnsignedOrNone LocalIndex = allocateTemporary(CE); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, CE)) @@ -810,7 +810,7 @@ bool Compiler::VisitImaginaryLiteral(const ImaginaryLiteral *E) { return true; if (!Initializing) { - std::optional LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -911,7 +911,7 @@ bool Compiler::VisitBinaryOperator(const BinaryOperator *BO) { // We need a temporary variable holding our return value. if (!Initializing) { - std::optional ResultIndex = this->allocateLocal(BO); + UnsignedOrNone ResultIndex = this->allocateLocal(BO); if (!this->emitGetPtrLocal(*ResultIndex, BO)) return false; } @@ -1151,7 +1151,7 @@ template bool Compiler::VisitComplexBinOp(const BinaryOperator *E) { // Prepare storage for result. if (!Initializing) { - std::optional LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -1210,7 +1210,7 @@ bool Compiler::VisitComplexBinOp(const BinaryOperator *E) { if (!LHSIsComplex) { // This is using the RHS type for the fake-complex LHS. - std::optional LocalIndex = allocateTemporary(RHS); + UnsignedOrNone LocalIndex = allocateTemporary(RHS); if (!LocalIndex) return false; LHSOffset = *LocalIndex; @@ -1385,7 +1385,7 @@ bool Compiler::VisitVectorBinOp(const BinaryOperator *E) { // Prepare storage for result. if (!Initializing && !E->isCompoundAssignmentOp()) { - std::optional LocalIndex = allocateTemporary(E); + UnsignedOrNone LocalIndex = allocateTemporary(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -2099,7 +2099,7 @@ bool Compiler::visitCallArgs(ArrayRef Args, ExplicitMemberFn); } - std::optional LocalIndex = + UnsignedOrNone LocalIndex = allocateLocal(std::move(Source), Arg->getType(), /*ExtendingDecl=*/nullptr, ScopeKind::Call); if (!LocalIndex) @@ -2942,7 +2942,7 @@ bool Compiler::VisitMaterializeTemporaryExpr( return false; const Expr *Inner = E->getSubExpr()->skipRValueSubobjectAdjustments(); - if (std::optional LocalIndex = + if (UnsignedOrNone LocalIndex = allocateLocal(E, Inner->getType(), E->getExtendingDecl())) { InitLinkScope ILS(this, InitLink::Temp(*LocalIndex)); if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -3019,7 +3019,7 @@ bool Compiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { unsigned LocalIndex; if (T) LocalIndex = this->allocateLocalPrimitive(Init, *T, /*IsConst=*/false); - else if (std::optional MaybeIndex = this->allocateLocal(Init)) + else if (UnsignedOrNone MaybeIndex = this->allocateLocal(Init)) LocalIndex = *MaybeIndex; else return false; @@ -3196,7 +3196,7 @@ bool Compiler::VisitCXXConstructExpr(const CXXConstructExpr *E) { if (Ctor->isTrivial()) return true; assert(!Initializing); - std::optional LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; @@ -3406,7 +3406,7 @@ bool Compiler::VisitCXXScalarValueInitExpr( if (const auto *CT = Ty->getAs()) { if (!Initializing) { - std::optional LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -3429,7 +3429,7 @@ bool Compiler::VisitCXXScalarValueInitExpr( if (const auto *VT = Ty->getAs()) { // FIXME: Code duplication with the _Complex case above. if (!Initializing) { - std::optional LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -4055,8 +4055,7 @@ bool Compiler::VisitExtVectorElementExpr( // Now the vector variable for the return value. if (!Initializing) { - std::optional ResultIndex; - ResultIndex = allocateLocal(E); + UnsignedOrNone ResultIndex = allocateLocal(E); if (!ResultIndex) return false; if (!this->emitGetPtrLocal(*ResultIndex, E)) @@ -4180,7 +4179,7 @@ template bool Compiler::visit(const Expr *E) { // Create local variable to hold the return value. if (!E->isGLValue() && !E->getType()->isAnyComplexType() && !canClassify(E->getType())) { - std::optional LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; @@ -4547,10 +4546,10 @@ unsigned Compiler::allocateLocalPrimitive( } template -std::optional -Compiler::allocateLocal(DeclTy &&Src, QualType Ty, - const ValueDecl *ExtendingDecl, ScopeKind SC, - bool IsConstexprUnknown) { +UnsignedOrNone Compiler::allocateLocal(DeclTy &&Src, QualType Ty, + const ValueDecl *ExtendingDecl, + ScopeKind SC, + bool IsConstexprUnknown) { const ValueDecl *Key = nullptr; const Expr *Init = nullptr; bool IsTemporary = false; @@ -4584,7 +4583,7 @@ Compiler::allocateLocal(DeclTy &&Src, QualType Ty, } template -std::optional Compiler::allocateTemporary(const Expr *E) { +UnsignedOrNone Compiler::allocateTemporary(const Expr *E) { QualType Ty = E->getType(); assert(!Ty->isRecordType()); @@ -4663,7 +4662,7 @@ bool Compiler::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 LocalOffset = this->allocateLocal(E)) { + if (UnsignedOrNone LocalOffset = this->allocateLocal(E)) { InitLinkScope ILS(this, InitLink::Temp(*LocalOffset)); if (!this->emitGetPtrLocal(*LocalOffset, E)) return false; @@ -4860,7 +4859,7 @@ VarCreationState Compiler::visitVarDecl(const VarDecl *VD, return this->emitSetLocal(*VarT, Offset, VD); } } else { - if (std::optional Offset = this->allocateLocal( + if (UnsignedOrNone Offset = this->allocateLocal( VD, VD->getType(), nullptr, ScopeKind::Block, IsConstexprUnknown)) { if (!Init) return true; @@ -5012,7 +5011,7 @@ bool Compiler::VisitBuiltinCallExpr(const CallExpr *E, // Non-primitive return type. Prepare storage. if (!Initializing && !ReturnT && !ReturnType->isVoidType()) { - std::optional LocalIndex = allocateLocal(E); + UnsignedOrNone LocalIndex = allocateLocal(E); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -5108,7 +5107,7 @@ bool Compiler::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 LocalIndex = allocateLocal(E)) { + if (UnsignedOrNone LocalIndex = allocateLocal(E)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -5116,7 +5115,7 @@ bool Compiler::VisitCallExpr(const CallExpr *E) { // We need the result. Prepare a pointer to return or // dup the current one. if (!Initializing) { - if (std::optional LocalIndex = allocateLocal(E)) { + if (UnsignedOrNone LocalIndex = allocateLocal(E)) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; } @@ -5152,7 +5151,7 @@ bool Compiler::VisitCallExpr(const CallExpr *E) { } bool Devirtualized = false; - std::optional CalleeOffset; + UnsignedOrNone CalleeOffset = std::nullopt; // Add the (optional, implicit) This pointer. if (const auto *MC = dyn_cast(E)) { if (!FuncDecl && classifyPrim(E->getCallee()) == PT_MemberPtr) { @@ -6560,7 +6559,7 @@ bool Compiler::VisitComplexUnaryOperator(const UnaryOperator *E) { OptPrimType ResT = classify(E); auto prepareResult = [=]() -> bool { if (!ResT && !Initializing) { - std::optional LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; return this->emitGetPtrLocal(*LocalIndex, E); @@ -6678,7 +6677,7 @@ bool Compiler::VisitVectorUnaryOperator(const UnaryOperator *E) { return this->delegate(SubExpr); if (!Initializing) { - std::optional LocalIndex = allocateLocal(SubExpr); + UnsignedOrNone LocalIndex = allocateLocal(SubExpr); if (!LocalIndex) return false; if (!this->emitGetPtrLocal(*LocalIndex, E)) @@ -7282,7 +7281,7 @@ bool Compiler::emitBuiltinBitCast(const CastExpr *E) { // Prepare storage for the result in case we discard. if (DiscardResult && !Initializing && !ToT) { - std::optional 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 cdf587cca663..475faee4d3fd 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -316,11 +316,11 @@ protected: bool IsConstexprUnknown = false); /// Allocates a space storing a local given its type. - std::optional - allocateLocal(DeclTy &&Decl, QualType Ty = QualType(), - const ValueDecl *ExtendingDecl = nullptr, - ScopeKind = ScopeKind::Block, bool IsConstexprUnknown = false); - std::optional 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; @@ -568,7 +568,7 @@ public: void addLocal(const Scope::Local &Local) override { if (!Idx) { - Idx = this->Ctx->Descriptors.size(); + Idx = static_cast(this->Ctx->Descriptors.size()); this->Ctx->Descriptors.emplace_back(); this->Ctx->emitInitScope(*Idx, {}); } @@ -616,7 +616,7 @@ public: } /// Index of the scope in the chain. - std::optional Idx; + UnsignedOrNone Idx = std::nullopt; }; /// Scope for storage declared in a compound statement.