[clang] d4f1f35 - [clang][Interp][NFC] Move to std::optional

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 5 08:32:04 PST 2022


Author: Timm Bäder
Date: 2022-12-05T17:31:49+01:00
New Revision: d4f1f35978c2593f7c52452d699a96899725452e

URL: https://github.com/llvm/llvm-project/commit/d4f1f35978c2593f7c52452d699a96899725452e
DIFF: https://github.com/llvm/llvm-project/commit/d4f1f35978c2593f7c52452d699a96899725452e.diff

LOG: [clang][Interp][NFC] Move to std::optional

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeEmitter.h
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/lib/AST/Interp/ByteCodeExprGen.h
    clang/lib/AST/Interp/ByteCodeStmtGen.cpp
    clang/lib/AST/Interp/ByteCodeStmtGen.h
    clang/lib/AST/Interp/Context.cpp
    clang/lib/AST/Interp/Context.h
    clang/lib/AST/Interp/EvalEmitter.cpp
    clang/lib/AST/Interp/EvalEmitter.h
    clang/lib/AST/Interp/InterpBlock.h
    clang/lib/AST/Interp/Pointer.h
    clang/lib/AST/Interp/Program.cpp
    clang/lib/AST/Interp/Program.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.h b/clang/lib/AST/Interp/ByteCodeEmitter.h
index e560d0ef38dd..30da06b20250 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -83,7 +83,7 @@ class ByteCodeEmitter {
   /// Offset of the next local variable.
   unsigned NextLocalOffset = 0;
   /// Location of a failure.
-  llvm::Optional<SourceLocation> BailLocation;
+  std::optional<SourceLocation> BailLocation;
   /// Label information for linker.
   llvm::DenseMap<LabelTy, unsigned> LabelOffsets;
   /// Location of label relocations.

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 48d4e98bf2eb..0c2eaac0e4e7 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -21,7 +21,6 @@ using namespace clang::interp;
 
 using APSInt = llvm::APSInt;
 template <typename T> using Expected = llvm::Expected<T>;
-template <typename T> using Optional = llvm::Optional<T>;
 
 namespace clang {
 namespace interp {
@@ -51,7 +50,7 @@ template <class Emitter> class OptionScope {
       : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
         OldInitFn(std::move(Ctx->InitFn)) {
     Ctx->DiscardResult = NewDiscardResult;
-    Ctx->InitFn = llvm::Optional<InitFnRef>{};
+    Ctx->InitFn = std::optional<InitFnRef>{};
   }
 
   /// Root constructor, setting up compilation state.
@@ -81,7 +80,7 @@ template <class Emitter> class OptionScope {
   /// Old discard flag to restore.
   bool OldDiscardResult;
   /// Old pointer emitter to restore.
-  llvm::Optional<InitFnRef> OldInitFn;
+  std::optional<InitFnRef> OldInitFn;
 };
 
 } // namespace interp
@@ -135,8 +134,8 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
 
   case CK_IntegralToBoolean:
   case CK_IntegralCast: {
-    Optional<PrimType> FromT = classify(SubExpr->getType());
-    Optional<PrimType> ToT = classify(CE->getType());
+    std::optional<PrimType> FromT = classify(SubExpr->getType());
+    std::optional<PrimType> ToT = classify(CE->getType());
     if (!FromT || !ToT)
       return false;
 
@@ -187,9 +186,9 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
   }
 
   // Typecheck the args.
-  Optional<PrimType> LT = classify(LHS->getType());
-  Optional<PrimType> RT = classify(RHS->getType());
-  Optional<PrimType> T = classify(BO->getType());
+  std::optional<PrimType> LT = classify(LHS->getType());
+  std::optional<PrimType> RT = classify(RHS->getType());
+  std::optional<PrimType> T = classify(BO->getType());
   if (!LT || !RT || !T) {
     return this->bail(BO);
   }
@@ -267,8 +266,8 @@ bool ByteCodeExprGen<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
       (!LHS->getType()->isPointerType() && !RHS->getType()->isPointerType()))
     return false;
 
-  Optional<PrimType> LT = classify(LHS);
-  Optional<PrimType> RT = classify(RHS);
+  std::optional<PrimType> LT = classify(LHS);
+  std::optional<PrimType> RT = classify(RHS);
 
   if (!LT || !RT)
     return false;
@@ -307,7 +306,7 @@ bool ByteCodeExprGen<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
-  if (Optional<PrimType> T = classify(E))
+  if (std::optional<PrimType> T = classify(E))
     return this->emitZero(*T, E);
 
   return false;
@@ -526,8 +525,8 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundAssignOperator(
     const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  Optional<PrimType> LT = classify(E->getLHS()->getType());
-  Optional<PrimType> RT = classify(E->getRHS()->getType());
+  std::optional<PrimType> LT = classify(E->getLHS()->getType());
+  std::optional<PrimType> RT = classify(E->getRHS()->getType());
 
   if (!LT || !RT)
     return false;
@@ -591,7 +590,7 @@ bool ByteCodeExprGen<Emitter>::visit(const Expr *E) {
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visitBool(const Expr *E) {
-  if (Optional<PrimType> T = classify(E->getType())) {
+  if (std::optional<PrimType> T = classify(E->getType())) {
     return visit(E);
   } else {
     return this->bail(E);
@@ -629,7 +628,7 @@ template <class Emitter>
 bool ByteCodeExprGen<Emitter>::dereference(
     const Expr *LV, DerefKind AK, llvm::function_ref<bool(PrimType)> Direct,
     llvm::function_ref<bool(PrimType)> Indirect) {
-  if (Optional<PrimType> T = classify(LV->getType())) {
+  if (std::optional<PrimType> T = classify(LV->getType())) {
     if (!LV->refersToBitField()) {
       // Only primitive, non bit-field types can be dereferenced directly.
       if (auto *DE = dyn_cast<DeclRefExpr>(LV)) {
@@ -812,7 +811,7 @@ unsigned ByteCodeExprGen<Emitter>::allocateLocalPrimitive(DeclTy &&Src,
 }
 
 template <class Emitter>
-llvm::Optional<unsigned>
+std::optional<unsigned>
 ByteCodeExprGen<Emitter>::allocateLocal(DeclTy &&Src, bool IsExtended) {
   QualType Ty;
 
@@ -853,7 +852,7 @@ bool ByteCodeExprGen<Emitter>::visitArrayInitializer(const Expr *Initializer) {
   if (const auto *InitList = dyn_cast<InitListExpr>(Initializer)) {
     unsigned ElementIndex = 0;
     for (const Expr *Init : InitList->inits()) {
-      if (Optional<PrimType> T = classify(Init->getType())) {
+      if (std::optional<PrimType> T = classify(Init->getType())) {
         // Visit the primitive element like normal.
         if (!this->emitDupPtr(Init))
           return false;
@@ -890,7 +889,7 @@ bool ByteCodeExprGen<Emitter>::visitArrayInitializer(const Expr *Initializer) {
     //   the AILE's Common expr.
     const Expr *SubExpr = AILE->getSubExpr();
     size_t Size = AILE->getArraySize().getZExtValue();
-    Optional<PrimType> ElemT = classify(SubExpr->getType());
+    std::optional<PrimType> ElemT = classify(SubExpr->getType());
 
     // So, every iteration, we execute an assignment here
     // where the LHS is on the stack (the target array)
@@ -931,7 +930,7 @@ bool ByteCodeExprGen<Emitter>::visitArrayInitializer(const Expr *Initializer) {
     const auto *CAT = cast<ConstantArrayType>(AT);
     size_t NumElems = CAT->getSize().getZExtValue();
 
-    if (Optional<PrimType> ElemT = classify(CAT->getElementType())) {
+    if (std::optional<PrimType> ElemT = classify(CAT->getElementType())) {
       // TODO(perf): For int and bool types, we can probably just skip this
       //   since we memset our Block*s to 0 and so we have the desired value
       //   without this.
@@ -1016,7 +1015,7 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
       if (!this->emitDupPtr(Initializer))
         return false;
 
-      if (Optional<PrimType> T = classify(Init)) {
+      if (std::optional<PrimType> T = classify(Init)) {
         if (!this->visit(Init))
           return false;
 
@@ -1126,7 +1125,7 @@ bool ByteCodeExprGen<Emitter>::visitExpr(const Expr *Exp) {
   if (!visit(Exp))
     return false;
 
-  if (Optional<PrimType> T = classify(Exp))
+  if (std::optional<PrimType> T = classify(Exp))
     return this->emitRet(*T, Exp);
   else
     return this->emitRetValue(Exp);
@@ -1136,8 +1135,8 @@ template <class Emitter>
 bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
   const Expr *Init = VD->getInit();
 
-  if (Optional<unsigned> I = P.createGlobal(VD, Init)) {
-    if (Optional<PrimType> T = classify(VD->getType())) {
+  if (std::optional<unsigned> I = P.createGlobal(VD, Init)) {
+    if (std::optional<PrimType> T = classify(VD->getType())) {
       {
         // Primitive declarations - compute the value and set it.
         DeclScope<Emitter> LocalScope(this, VD);
@@ -1187,13 +1186,13 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
       return false;
 
     QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
-    Optional<PrimType> T = classify(ReturnType);
+    std::optional<PrimType> T = classify(ReturnType);
 
     if (Func->hasRVO() && DiscardResult) {
       // 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 (Optional<unsigned> LocalIndex = allocateLocal(E)) {
+      if (std::optional<unsigned> LocalIndex = allocateLocal(E)) {
         if (!this->emitGetPtrLocal(*LocalIndex, E))
           return false;
       }
@@ -1272,7 +1271,7 @@ bool ByteCodeExprGen<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
   const Expr *SubExpr = E->getSubExpr();
-  Optional<PrimType> T = classify(SubExpr->getType());
+  std::optional<PrimType> T = classify(SubExpr->getType());
 
   // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 9b5306594517..f817fb4aedef 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -22,7 +22,6 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/TargetInfo.h"
-#include "llvm/ADT/Optional.h"
 
 namespace clang {
 class QualType;
@@ -120,10 +119,10 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
   }
 
   /// Classifies a type.
-  llvm::Optional<PrimType> classify(const Expr *E) const {
+  std::optional<PrimType> classify(const Expr *E) const {
     return E->isGLValue() ? PT_Ptr : classify(E->getType());
   }
-  llvm::Optional<PrimType> classify(QualType Ty) const {
+  std::optional<PrimType> classify(QualType Ty) const {
     return Ctx.classify(Ty);
   }
 
@@ -192,8 +191,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
                                   bool IsExtended = false);
 
   /// Allocates a space storing a local given its type.
-  llvm::Optional<unsigned> allocateLocal(DeclTy &&Decl,
-                                         bool IsExtended = false);
+  std::optional<unsigned> allocateLocal(DeclTy &&Decl, bool IsExtended = false);
 
 private:
   friend class VariableScope<Emitter>;
@@ -264,13 +262,13 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
   VariableScope<Emitter> *VarScope = nullptr;
 
   /// Current argument index. Needed to emit ArrayInitIndexExpr.
-  llvm::Optional<uint64_t> ArrayIndex;
+  std::optional<uint64_t> ArrayIndex;
 
   /// Flag indicating if return value is to be discarded.
   bool DiscardResult = false;
 
   /// Expression being initialized.
-  llvm::Optional<InitFnRef> InitFn = {};
+  std::optional<InitFnRef> InitFn = {};
 };
 
 extern template class ByteCodeExprGen<ByteCodeEmitter>;
@@ -341,7 +339,7 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
 
 protected:
   /// Index of the scope in the chain.
-  Optional<unsigned> Idx;
+  std::optional<unsigned> Idx;
 };
 
 /// Scope for storage declared in a compound statement.
@@ -376,7 +374,7 @@ template <class Emitter> class ArrayIndexScope final {
 
 private:
   ByteCodeExprGen<Emitter> *Ctx;
-  Optional<uint64_t> OldArrayIndex;
+  std::optional<uint64_t> OldArrayIndex;
 };
 
 } // namespace interp

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 69b223299313..44997857f6a5 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -106,7 +106,7 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
       if (const FieldDecl *Member = Init->getMember()) {
         const Record::Field *F = R->getField(Member);
 
-        if (Optional<PrimType> T = this->classify(InitExpr)) {
+        if (std::optional<PrimType> T = this->classify(InitExpr)) {
           if (!this->emitThis(InitExpr))
             return false;
 
@@ -399,7 +399,7 @@ bool ByteCodeStmtGen<Emitter>::visitVarDecl(const VarDecl *VD) {
   }
 
   // Integers, pointers, primitives.
-  if (Optional<PrimType> T = this->classify(VD->getType())) {
+  if (std::optional<PrimType> T = this->classify(VD->getType())) {
     const Expr *Init = VD->getInit();
 
     if (!Init)
@@ -418,7 +418,7 @@ bool ByteCodeStmtGen<Emitter>::visitVarDecl(const VarDecl *VD) {
   }
 
   // Composite types - allocate storage and initialize it.
-  if (Optional<unsigned> Offset = this->allocateLocal(VD))
+  if (std::optional<unsigned> Offset = this->allocateLocal(VD))
     return this->visitLocalInitializer(VD->getInit(), *Offset);
 
   return this->bail(VD);

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 10452079c65b..2385c3e55c2f 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -22,7 +22,6 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/StmtVisitor.h"
-#include "llvm/ADT/Optional.h"
 
 namespace clang {
 namespace interp {
@@ -36,7 +35,7 @@ template <class Emitter>
 class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
   using LabelTy = typename Emitter::LabelTy;
   using AddrTy = typename Emitter::AddrTy;
-  using OptLabelTy = llvm::Optional<LabelTy>;
+  using OptLabelTy = std::optional<LabelTy>;
   using CaseMap = llvm::DenseMap<const SwitchCase *, LabelTy>;
 
 public:
@@ -69,7 +68,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
 
 private:
   /// Type of the expression returned by the function.
-  llvm::Optional<PrimType> ReturnType;
+  std::optional<PrimType> ReturnType;
 
   /// Switch case mapping.
   CaseMap CaseLabels;

diff  --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 1ca3d7515c57..6fd645b87d22 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -72,7 +72,7 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
 
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
 
-llvm::Optional<PrimType> Context::classify(QualType T) const {
+std::optional<PrimType> Context::classify(QualType T) const {
   if (T->isReferenceType() || T->isPointerType()) {
     return PT_Ptr;
   }

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index feb809b69bf3..e49422e64b87 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -59,7 +59,7 @@ class Context final {
   unsigned getCharBit() const;
 
   /// Classifies an expression.
-  llvm::Optional<PrimType> classify(QualType T) const;
+  std::optional<PrimType> classify(QualType T) const;
 
 private:
   /// Runs a function.

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index 22e8695b9211..12854c1c0437 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -123,7 +123,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
           const Pointer &FP = Ptr.atField(F.Offset);
           QualType FieldTy = F.Decl->getType();
           if (FP.isActive()) {
-            if (llvm::Optional<PrimType> T = Ctx.classify(FieldTy)) {
+            if (std::optional<PrimType> T = Ctx.classify(FieldTy)) {
               TYPE_SWITCH(*T, Ok &= ReturnValue<T>(FP.deref<T>(), Value));
             } else {
               Ok &= Composite(FieldTy, FP, Value);
@@ -145,7 +145,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
           const Pointer &FP = Ptr.atField(FD->Offset);
           APValue &Value = R.getStructField(I);
 
-          if (llvm::Optional<PrimType> T = Ctx.classify(FieldTy)) {
+          if (std::optional<PrimType> T = Ctx.classify(FieldTy)) {
             TYPE_SWITCH(*T, Ok &= ReturnValue<T>(FP.deref<T>(), Value));
           } else {
             Ok &= Composite(FieldTy, FP, Value);
@@ -177,7 +177,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
       for (unsigned I = 0; I < NumElems; ++I) {
         APValue &Slot = R.getArrayInitializedElt(I);
         const Pointer &EP = Ptr.atIndex(I);
-        if (llvm::Optional<PrimType> T = Ctx.classify(ElemTy)) {
+        if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
           TYPE_SWITCH(*T, Ok &= ReturnValue<T>(EP.deref<T>(), Slot));
         } else {
           Ok &= Composite(ElemTy, EP.narrow(), Slot);

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h b/clang/lib/AST/Interp/EvalEmitter.h
index 72433778f23f..6b6d0d621901 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -96,7 +96,7 @@ class EvalEmitter : public SourceMapper {
   // value which is mapped to the location of the opcode being evaluated.
   CodePtr OpPC;
   /// Location of a failure.
-  llvm::Optional<SourceLocation> BailLocation;
+  std::optional<SourceLocation> BailLocation;
   /// Location of the current instruction.
   SourceInfo CurrentSource;
 

diff  --git a/clang/lib/AST/Interp/InterpBlock.h b/clang/lib/AST/Interp/InterpBlock.h
index 9c0b5612b9fa..b8b5b39f55d4 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -35,7 +35,7 @@ enum PrimType : unsigned;
 class Block final {
 public:
   // Creates a new block.
-  Block(const llvm::Optional<unsigned> &DeclID, Descriptor *Desc,
+  Block(const std::optional<unsigned> &DeclID, Descriptor *Desc,
         bool IsStatic = false, bool IsExtern = false)
       : DeclID(DeclID), IsStatic(IsStatic), IsExtern(IsExtern), Desc(Desc) {}
 
@@ -56,7 +56,7 @@ class Block final {
   /// Returns the size of the block.
   InterpSize getSize() const { return Desc->getAllocSize(); }
   /// Returns the declaration ID.
-  llvm::Optional<unsigned> getDeclID() const { return DeclID; }
+  std::optional<unsigned> getDeclID() const { return DeclID; }
 
   /// Returns a pointer to the stored data.
   char *data() { return reinterpret_cast<char *>(this + 1); }
@@ -98,7 +98,7 @@ class Block final {
   /// Start of the chain of pointers.
   Pointer *Pointers = nullptr;
   /// Unique identifier of the declaration.
-  llvm::Optional<unsigned> DeclID;
+  std::optional<unsigned> DeclID;
   /// Flag indicating if the block has static storage duration.
   bool IsStatic = false;
   /// Flag indicating if the block is an extern.

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 587531aec82a..09738fbfb137 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -246,7 +246,7 @@ class Pointer {
   }
 
   /// Returns the declaration ID.
-  llvm::Optional<unsigned> getDeclID() const { return Pointee->getDeclID(); }
+  std::optional<unsigned> getDeclID() const { return Pointee->getDeclID(); }
 
   /// Returns the byte offset from the start.
   unsigned getByteOffset() const {

diff  --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp
index 85f363533e5f..3e1d0bc6ad20 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -100,13 +100,13 @@ Pointer Program::getPtrGlobal(unsigned Idx) {
   return Pointer(Globals[Idx]->block());
 }
 
-llvm::Optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
+std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
   auto It = GlobalIndices.find(VD);
   if (It != GlobalIndices.end())
     return It->second;
 
   // Find any previous declarations which were already evaluated.
-  llvm::Optional<unsigned> Index;
+  std::optional<unsigned> Index;
   for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
     auto It = GlobalIndices.find(P);
     if (It != GlobalIndices.end()) {
@@ -124,7 +124,7 @@ llvm::Optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
   return Index;
 }
 
-llvm::Optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD) {
+std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD) {
   if (auto Idx = getGlobal(VD))
     return Idx;
 
@@ -135,7 +135,7 @@ llvm::Optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD) {
   return {};
 }
 
-llvm::Optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) {
+std::optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) {
   auto &ASTCtx = Ctx.getASTContext();
 
   // Create a pointer to an incomplete array of the specified elements.
@@ -154,8 +154,8 @@ llvm::Optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) {
   return {};
 }
 
-llvm::Optional<unsigned> Program::createGlobal(const ValueDecl *VD,
-                                               const Expr *Init) {
+std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
+                                              const Expr *Init) {
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast<VarDecl>(VD)) {
     IsStatic = !Var->hasLocalStorage();
@@ -172,13 +172,13 @@ llvm::Optional<unsigned> Program::createGlobal(const ValueDecl *VD,
   return {};
 }
 
-llvm::Optional<unsigned> Program::createGlobal(const Expr *E) {
+std::optional<unsigned> Program::createGlobal(const Expr *E) {
   return createGlobal(E, E->getType(), /*isStatic=*/true, /*isExtern=*/false);
 }
 
-llvm::Optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
-                                               bool IsStatic, bool IsExtern,
-                                               const Expr *Init) {
+std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
+                                              bool IsStatic, bool IsExtern,
+                                              const Expr *Init) {
   // Create a descriptor for the global.
   Descriptor *Desc;
   const bool IsConst = Ty.isConstQualified();
@@ -285,7 +285,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
     const bool IsConst = FT.isConstQualified();
     const bool IsMutable = FD->isMutable();
     Descriptor *Desc;
-    if (llvm::Optional<PrimType> T = Ctx.classify(FT)) {
+    if (std::optional<PrimType> T = Ctx.classify(FT)) {
       Desc = createDescriptor(FD, *T, IsConst, /*isTemporary=*/false,
                               IsMutable);
     } else {
@@ -319,7 +319,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
     // Array of well-known bounds.
     if (auto CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
       size_t NumElems = CAT->getSize().getZExtValue();
-      if (llvm::Optional<PrimType> T = Ctx.classify(ElemTy)) {
+      if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
         // Arrays of primitives.
         unsigned ElemSize = primSize(*T);
         if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
@@ -346,7 +346,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
     // Array of unknown bounds - cannot be accessed and pointer arithmetic
     // is forbidden on pointers to such objects.
     if (isa<IncompleteArrayType>(ArrayType)) {
-      if (llvm::Optional<PrimType> T = Ctx.classify(ElemTy)) {
+      if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
         return allocateDescriptor(D, *T, IsTemporary,
                                   Descriptor::UnknownSize{});
       } else {

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 94bfd2697d26..c5591c58e457 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -76,19 +76,19 @@ class Program final {
   }
 
   /// Finds a global's index.
-  llvm::Optional<unsigned> getGlobal(const ValueDecl *VD);
+  std::optional<unsigned> getGlobal(const ValueDecl *VD);
 
   /// Returns or creates a global an creates an index to it.
-  llvm::Optional<unsigned> getOrCreateGlobal(const ValueDecl *VD);
+  std::optional<unsigned> getOrCreateGlobal(const ValueDecl *VD);
 
   /// Returns or creates a dummy value for parameters.
-  llvm::Optional<unsigned> getOrCreateDummy(const ParmVarDecl *PD);
+  std::optional<unsigned> getOrCreateDummy(const ParmVarDecl *PD);
 
   /// Creates a global and returns its index.
-  llvm::Optional<unsigned> createGlobal(const ValueDecl *VD, const Expr *E);
+  std::optional<unsigned> createGlobal(const ValueDecl *VD, const Expr *E);
 
   /// Creates a global from a lifetime-extended temporary.
-  llvm::Optional<unsigned> createGlobal(const Expr *E);
+  std::optional<unsigned> createGlobal(const Expr *E);
 
   /// Creates a new function from a code range.
   template <typename... Ts>
@@ -137,18 +137,18 @@ class Program final {
   };
 
   /// Returns the current declaration ID.
-  llvm::Optional<unsigned> getCurrentDecl() const {
+  std::optional<unsigned> getCurrentDecl() const {
     if (CurrentDeclaration == NoDeclaration)
-      return llvm::Optional<unsigned>{};
+      return std::optional<unsigned>{};
     return LastDeclaration;
   }
 
 private:
   friend class DeclScope;
 
-  llvm::Optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
-                                        bool IsStatic, bool IsExtern,
-                                        const Expr *Init = nullptr);
+  std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
+                                       bool IsStatic, bool IsExtern,
+                                       const Expr *Init = nullptr);
 
   /// Reference to the VM context.
   Context &Ctx;


        


More information about the cfe-commits mailing list