[llvm] 9408164 - [FileCheck] llvm::Optional => std::optional

Voss, Matthew via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 11:19:20 PST 2022


Hi Maskray,

We're seeing a build failure internally and on these buildbots after this change. Could you take a look? Sorry for the double ping, but our CI is blocked by this.

https://lab.llvm.org/staging/#/builders/235/builds/993
https://lab.llvm.org/buildbot/#/builders/216/builds/14436

Thanks,
Matt 

> -----Original Message-----
> From: llvm-commits <llvm-commits-bounces at lists.llvm.org> On Behalf Of
> Fangrui Song via llvm-commits
> Sent: Wednesday, December 14, 2022 10:45 AM
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] 9408164 - [FileCheck] llvm::Optional => std::optional
> 
> 
> Author: Fangrui Song
> Date: 2022-12-14T18:44:30Z
> New Revision: 9408164254d26d5305fe4e0267b668c41c1266ed
> 
> URL: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> project/commit/9408164254d26d5305fe4e0267b668c41c1266ed__;!!JmoZiZGB
> v3RvKRSx!-3MGJ3moHIlSrHaTGNWpImARD69Bqt_7EtrAA6dZ_qnC-
> 7ene0pXMGBxC8AKJf1-vqTcsIiAhkXyx-L1hCSwBNHwH76j$
> DIFF: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> project/commit/9408164254d26d5305fe4e0267b668c41c1266ed.diff__;!!JmoZi
> ZGBv3RvKRSx!-3MGJ3moHIlSrHaTGNWpImARD69Bqt_7EtrAA6dZ_qnC-
> 7ene0pXMGBxC8AKJf1-vqTcsIiAhkXyx-L1hCSwBJltQ0id$
> 
> LOG: [FileCheck] llvm::Optional => std::optional
> 
> Don't touch FileCheck.cpp:698
> StringSwitch<Optional<binop_eval_t>>(FuncName).
> MSVC and older GCC may report errors:
> 
> error C2664: 'llvm::StringSwitch<std::optional<llvm::binop_eval_t>,T>
> &llvm::StringSwitch<T,T>::Case(llvm::StringLiteral,T)': cannot convert argument
> 2 from 'overloaded-function' to 'T'
>         with
>         [
>             T=std::optional<llvm::binop_eval_t>
>         ]
> 
> llvm/lib/FileCheck/FileCheck.cpp:699:44: error: no matching function for call to
> ‘llvm::StringSwitch<std::optional<llvm::Expected<llvm::ExpressionValue>
> (*)(const llvm::ExpressionValue&, const llvm::ExpressionValue&)> >::Case(const
> char [4], <unresolved overloaded function type>)’
>                       .Case("add", operator+)
>                                             ^
> 
> Added:
> 
> 
> Modified:
>     llvm/lib/FileCheck/FileCheck.cpp
>     llvm/lib/FileCheck/FileCheckImpl.h
>     llvm/unittests/FileCheck/FileCheckTest.cpp
> 
> Removed:
> 
> 
> 
> #################################################################
> ###############
> diff  --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
> index e2cc6dc6763bb..119d369747bc4 100644
> --- a/llvm/lib/FileCheck/FileCheck.cpp
> +++ b/llvm/lib/FileCheck/FileCheck.cpp
> @@ -363,7 +363,7 @@ Expected<ExpressionValue> llvm::min(const
> ExpressionValue &LeftOperand,  }
> 
>  Expected<ExpressionValue> NumericVariableUse::eval() const {
> -  Optional<ExpressionValue> Value = Variable->getValue();
> +  std::optional<ExpressionValue> Value = Variable->getValue();
>    if (Value)
>      return *Value;
> 
> @@ -480,7 +480,7 @@ char ErrorReported::ID = 0;
> 
>  Expected<NumericVariable *> Pattern::parseNumericVariableDefinition(
>      StringRef &Expr, FileCheckPatternContext *Context,
> -    Optional<size_t> LineNumber, ExpressionFormat ImplicitFormat,
> +    std::optional<size_t> LineNumber, ExpressionFormat ImplicitFormat,
>      const SourceMgr &SM) {
>    Expected<VariableProperties> ParseVarResult = parseVariable(Expr, SM);
>    if (!ParseVarResult)
> @@ -518,7 +518,7 @@ Expected<NumericVariable *>
> Pattern::parseNumericVariableDefinition(
>  }
> 
>  Expected<std::unique_ptr<NumericVariableUse>>
> Pattern::parseNumericVariableUse(
> -    StringRef Name, bool IsPseudo, Optional<size_t> LineNumber,
> +    StringRef Name, bool IsPseudo, std::optional<size_t> LineNumber,
>      FileCheckPatternContext *Context, const SourceMgr &SM) {
>    if (IsPseudo && !Name.equals("@LINE"))
>      return ErrorDiagnostic::get(
> @@ -542,7 +542,7 @@ Expected<std::unique_ptr<NumericVariableUse>>
> Pattern::parseNumericVariableUse(
>      Context->GlobalNumericVariableTable[Name] = NumericVariable;
>    }
> 
> -  Optional<size_t> DefLineNumber = NumericVariable->getDefLineNumber();
> +  std::optional<size_t> DefLineNumber =
> + NumericVariable->getDefLineNumber();
>    if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber)
>      return ErrorDiagnostic::get(
>          SM, Name,
> @@ -554,7 +554,7 @@ Expected<std::unique_ptr<NumericVariableUse>>
> Pattern::parseNumericVariableUse(
> 
>  Expected<std::unique_ptr<ExpressionAST>> Pattern::parseNumericOperand(
>      StringRef &Expr, AllowedOperand AO, bool MaybeInvalidConstraint,
> -    Optional<size_t> LineNumber, FileCheckPatternContext *Context,
> +    std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
>      const SourceMgr &SM) {
>    if (Expr.startswith("(")) {
>      if (AO != AllowedOperand::Any)
> @@ -611,7 +611,7 @@ Expected<std::unique_ptr<ExpressionAST>>
> Pattern::parseNumericOperand(  }
> 
>  Expected<std::unique_ptr<ExpressionAST>>
> -Pattern::parseParenExpr(StringRef &Expr, Optional<size_t> LineNumber,
> +Pattern::parseParenExpr(StringRef &Expr, std::optional<size_t>
> +LineNumber,
>                          FileCheckPatternContext *Context, const SourceMgr &SM) {
>    Expr = Expr.ltrim(SpaceChars);
>    assert(Expr.startswith("("));
> @@ -646,7 +646,7 @@ Pattern::parseParenExpr(StringRef &Expr,
> Optional<size_t> LineNumber,  Expected<std::unique_ptr<ExpressionAST>>
>  Pattern::parseBinop(StringRef Expr, StringRef &RemainingExpr,
>                      std::unique_ptr<ExpressionAST> LeftOp,
> -                    bool IsLegacyLineExpr, Optional<size_t> LineNumber,
> +                    bool IsLegacyLineExpr, std::optional<size_t>
> + LineNumber,
>                      FileCheckPatternContext *Context, const SourceMgr &SM) {
>    RemainingExpr = RemainingExpr.ltrim(SpaceChars);
>    if (RemainingExpr.empty())
> @@ -690,7 +690,7 @@ Pattern::parseBinop(StringRef Expr, StringRef
> &RemainingExpr,
> 
>  Expected<std::unique_ptr<ExpressionAST>>
>  Pattern::parseCallExpr(StringRef &Expr, StringRef FuncName,
> -                       Optional<size_t> LineNumber,
> +                       std::optional<size_t> LineNumber,
>                         FileCheckPatternContext *Context, const SourceMgr &SM) {
>    Expr = Expr.ltrim(SpaceChars);
>    assert(Expr.startswith("("));
> @@ -765,8 +765,8 @@ Pattern::parseCallExpr(StringRef &Expr, StringRef
> FuncName,  }
> 
>  Expected<std::unique_ptr<Expression>>
> Pattern::parseNumericSubstitutionBlock(
> -    StringRef Expr, Optional<NumericVariable *> &DefinedNumericVariable,
> -    bool IsLegacyLineExpr, Optional<size_t> LineNumber,
> +    StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
> +    bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
>      FileCheckPatternContext *Context, const SourceMgr &SM) {
>    std::unique_ptr<ExpressionAST> ExpressionASTPointer = nullptr;
>    StringRef DefExpr = StringRef();
> @@ -1099,7 +1099,7 @@ bool Pattern::parsePattern(StringRef PatternStr,
> StringRef Prefix,
> 
>        // Parse numeric substitution block.
>        std::unique_ptr<Expression> ExpressionPointer;
> -      Optional<NumericVariable *> DefinedNumericVariable;
> +      std::optional<NumericVariable *> DefinedNumericVariable;
>        if (IsNumBlock) {
>          Expected<std::unique_ptr<Expression>> ParseResult =
>              parseNumericSubstitutionBlock(MatchStr, DefinedNumericVariable, @@
> -1412,7 +1412,7 @@ void Pattern::printVariableDefs(const SourceMgr &SM,
>    for (const auto &VariableDef : NumericVariableDefs) {
>      VarCapture VC;
>      VC.Name = VariableDef.getKey();
> -    Optional<StringRef> StrValue =
> +    std::optional<StringRef> StrValue =
>          VariableDef.getValue().DefinedNumericVariable->getStringValue();
>      if (!StrValue)
>        continue;
> @@ -2701,7 +2701,7 @@ Error
> FileCheckPatternContext::defineCmdlineVariables(
>        // Now parse the definition both to check that the syntax is correct and
>        // to create the necessary class instance.
>        StringRef CmdlineDefExpr = CmdlineDef.substr(1);
> -      Optional<NumericVariable *> DefinedNumericVariable;
> +      std::optional<NumericVariable *> DefinedNumericVariable;
>        Expected<std::unique_ptr<Expression>> ExpressionResult =
>            Pattern::parseNumericSubstitutionBlock(CmdlineDefExpr,
>                                                   DefinedNumericVariable, false,
> 
> diff  --git a/llvm/lib/FileCheck/FileCheckImpl.h
> b/llvm/lib/FileCheck/FileCheckImpl.h
> index 556be6b8bb0f9..fd3568e7a5b06 100644
> --- a/llvm/lib/FileCheck/FileCheckImpl.h
> +++ b/llvm/lib/FileCheck/FileCheckImpl.h
> @@ -15,13 +15,13 @@
>  #ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
>  #define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
> 
> -#include "llvm/ADT/Optional.h"
>  #include "llvm/ADT/StringMap.h"
>  #include "llvm/ADT/StringRef.h"
>  #include "llvm/FileCheck/FileCheck.h"
>  #include "llvm/Support/Error.h"
>  #include "llvm/Support/SourceMgr.h"
>  #include <map>
> +#include <optional>
>  #include <string>
>  #include <vector>
> 
> @@ -266,23 +266,23 @@ class NumericVariable {
>    ExpressionFormat ImplicitFormat;
> 
>    /// Value of numeric variable, if defined, or std::nullopt otherwise.
> -  Optional<ExpressionValue> Value;
> +  std::optional<ExpressionValue> Value;
> 
>    /// The input buffer's string from which Value was parsed, or std::nullopt.
>    /// See comments on getStringValue for a discussion of the None case.
> -  Optional<StringRef> StrValue;
> +  std::optional<StringRef> StrValue;
> 
>    /// Line number where this variable is defined, or std::nullopt if defined
>    /// before input is parsed. Used to determine whether a variable is defined on
>    /// the same line as a given use.
> -  Optional<size_t> DefLineNumber;
> +  std::optional<size_t> DefLineNumber;
> 
>  public:
>    /// Constructor for a variable \p Name with implicit format \p ImplicitFormat
>    /// defined at line \p DefLineNumber or defined before input is parsed if
>    /// \p DefLineNumber is None.
>    explicit NumericVariable(StringRef Name, ExpressionFormat ImplicitFormat,
> -                           Optional<size_t> DefLineNumber = std::nullopt)
> +                           std::optional<size_t> DefLineNumber =
> + std::nullopt)
>        : Name(Name), ImplicitFormat(ImplicitFormat),
>          DefLineNumber(DefLineNumber) {}
> 
> @@ -293,20 +293,20 @@ class NumericVariable {
>    ExpressionFormat getImplicitFormat() const { return ImplicitFormat; }
> 
>    /// \returns this variable's value.
> -  Optional<ExpressionValue> getValue() const { return Value; }
> +  std::optional<ExpressionValue> getValue() const { return Value; }
> 
>    /// \returns the input buffer's string from which this variable's value was
>    /// parsed, or std::nullopt if the value is not yet defined or was not parsed
>    /// from the input buffer.  For example, the value of @LINE is not parsed from
>    /// the input buffer, and some numeric variables are parsed from the
> command
>    /// line instead.
> -  Optional<StringRef> getStringValue() const { return StrValue; }
> +  std::optional<StringRef> getStringValue() const { return StrValue; }
> 
>    /// Sets value of this numeric variable to \p NewValue, and sets the input
>    /// buffer string from which it was parsed to \p NewStrValue.  See comments
> on
>    /// getStringValue for a discussion of when the latter can be None.
>    void setValue(ExpressionValue NewValue,
> -                Optional<StringRef> NewStrValue = std::nullopt) {
> +                std::optional<StringRef> NewStrValue = std::nullopt) {
>      Value = NewValue;
>      StrValue = NewStrValue;
>    }
> @@ -320,7 +320,7 @@ class NumericVariable {
> 
>    /// \returns the line number where this variable is defined, if any, or
>    /// std::nullopt if defined before input is parsed.
> -  Optional<size_t> getDefLineNumber() const { return DefLineNumber; }
> +  std::optional<size_t> getDefLineNumber() const { return
> + DefLineNumber; }
>  };
> 
>  /// Class representing the use of a numeric variable in the AST of an @@ -
> 675,14 +675,14 @@ class Pattern {
>    /// Line number for this CHECK pattern or std::nullopt if it is an implicit
>    /// pattern. Used to determine whether a variable definition is made on an
>    /// earlier line to the one with this CHECK.
> -  Optional<size_t> LineNumber;
> +  std::optional<size_t> LineNumber;
> 
>    /// Ignore case while matching if set to true.
>    bool IgnoreCase = false;
> 
>  public:
>    Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context,
> -          Optional<size_t> Line = std::nullopt)
> +          std::optional<size_t> Line = std::nullopt)
>        : Context(Context), CheckTy(Ty), LineNumber(Line) {}
> 
>    /// \returns the location in source code.
> @@ -719,8 +719,8 @@ class Pattern {
>    /// representing the numeric variable defined in this numeric substitution
>    /// block, or std::nullopt if this block does not define any variable.
>    static Expected<std::unique_ptr<Expression>> parseNumericSubstitutionBlock(
> -      StringRef Expr, Optional<NumericVariable *> &DefinedNumericVariable,
> -      bool IsLegacyLineExpr, Optional<size_t> LineNumber,
> +      StringRef Expr, std::optional<NumericVariable *>
> &DefinedNumericVariable,
> +      bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
>        FileCheckPatternContext *Context, const SourceMgr &SM);
>    /// Parses the pattern in \p PatternStr and initializes this Pattern instance
>    /// accordingly.
> @@ -736,7 +736,7 @@ class Pattern {
>      size_t Len;
>    };
>    struct MatchResult {
> -    Optional<Match> TheMatch;
> +    std::optional<Match> TheMatch;
>      Error TheError;
>      MatchResult(size_t MatchPos, size_t MatchLen, Error E)
>          : TheMatch(Match{MatchPos, MatchLen}), TheError(std::move(E)) {} @@ -
> 794,7 +794,7 @@ class Pattern {
>    /// should defining such a variable be invalid.
>    static Expected<NumericVariable *> parseNumericVariableDefinition(
>        StringRef &Expr, FileCheckPatternContext *Context,
> -      Optional<size_t> LineNumber, ExpressionFormat ImplicitFormat,
> +      std::optional<size_t> LineNumber, ExpressionFormat
> + ImplicitFormat,
>        const SourceMgr &SM);
>    /// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use
>    /// at line \p LineNumber, or before input is parsed if \p LineNumber is @@ -
> 803,7 +803,7 @@ class Pattern {
>    /// representing that variable if successful, or an error holding a
>    /// diagnostic against \p SM otherwise.
>    static Expected<std::unique_ptr<NumericVariableUse>>
> parseNumericVariableUse(
> -      StringRef Name, bool IsPseudo, Optional<size_t> LineNumber,
> +      StringRef Name, bool IsPseudo, std::optional<size_t> LineNumber,
>        FileCheckPatternContext *Context, const SourceMgr &SM);
>    enum class AllowedOperand { LineVar, LegacyLiteral, Any };
>    /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or @@
> -817,7 +817,7 @@ class Pattern {
>    /// function will attempt to parse a parenthesized expression.
>    static Expected<std::unique_ptr<ExpressionAST>>
>    parseNumericOperand(StringRef &Expr, AllowedOperand AO, bool
> ConstraintParsed,
> -                      Optional<size_t> LineNumber,
> +                      std::optional<size_t> LineNumber,
>                        FileCheckPatternContext *Context, const SourceMgr &SM);
>    /// Parses and updates \p RemainingExpr for a binary operation at line
>    /// \p LineNumber, or before input is parsed if \p LineNumber is None. The
> @@ -831,7 +831,7 @@ class Pattern {
>    static Expected<std::unique_ptr<ExpressionAST>>
>    parseBinop(StringRef Expr, StringRef &RemainingExpr,
>               std::unique_ptr<ExpressionAST> LeftOp, bool IsLegacyLineExpr,
> -             Optional<size_t> LineNumber, FileCheckPatternContext *Context,
> +             std::optional<size_t> LineNumber, FileCheckPatternContext
> + *Context,
>               const SourceMgr &SM);
> 
>    /// Parses a parenthesized expression inside \p Expr at line \p LineNumber, or
> @@ -841,7 +841,7 @@ class Pattern {
>    /// variables. \returns the class representing that operand in the AST of the
>    /// expression or an error holding a diagnostic against \p SM otherwise.
>    static Expected<std::unique_ptr<ExpressionAST>>
> -  parseParenExpr(StringRef &Expr, Optional<size_t> LineNumber,
> +  parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
>                   FileCheckPatternContext *Context, const SourceMgr &SM);
> 
>    /// Parses \p Expr for an argument list belonging to a call to function \p @@ -
> 853,8 +853,8 @@ class Pattern {
>    /// otherwise.
>    static Expected<std::unique_ptr<ExpressionAST>>
>    parseCallExpr(StringRef &Expr, StringRef FuncName,
> -                Optional<size_t> LineNumber, FileCheckPatternContext *Context,
> -                const SourceMgr &SM);
> +                std::optional<size_t> LineNumber,
> +                FileCheckPatternContext *Context, const SourceMgr &SM);
>  };
> 
>  //===----------------------------------------------------------------------===//
> 
> diff  --git a/llvm/unittests/FileCheck/FileCheckTest.cpp
> b/llvm/unittests/FileCheck/FileCheckTest.cpp
> index c31c553470dd1..8f7512844e8d7 100644
> --- a/llvm/unittests/FileCheck/FileCheckTest.cpp
> +++ b/llvm/unittests/FileCheck/FileCheckTest.cpp
> @@ -750,7 +750,7 @@ TEST_F(FileCheckTest, NumericVariable) {
> 
>    // Defined variable without string: only getValue and eval return value set.
>    FooVar.setValue(ExpressionValue(42u));
> -  Optional<ExpressionValue> Value = FooVar.getValue();
> +  std::optional<ExpressionValue> Value = FooVar.getValue();
>    ASSERT_TRUE(Value);
>    EXPECT_EQ(42, cantFail(Value->getSignedValue()));
>    EXPECT_FALSE(FooVar.getStringValue());
> @@ -1014,7 +1014,7 @@ class PatternTester {
>    Expected<std::unique_ptr<Expression>>
>    parseSubst(StringRef Expr, bool IsLegacyLineExpr = false) {
>      StringRef ExprBufferRef = bufferize(SM, Expr);
> -    Optional<NumericVariable *> DefinedNumericVariable;
> +    std::optional<NumericVariable *> DefinedNumericVariable;
>      return P.parseNumericSubstitutionBlock(
>          ExprBufferRef, DefinedNumericVariable, IsLegacyLineExpr, LineNumber,
>          &Context, SM);
> @@ -1665,7 +1665,7 @@ TEST_F(FileCheckTest, FileCheckContext) {
>    StringRef UnknownVarStr = "UnknownVar";
>    Expected<StringRef> LocalVar = Cxt.getPatternVarValue(LocalVarStr);
>    P = Pattern(Check::CheckPlain, &Cxt, ++LineNumber);
> -  Optional<NumericVariable *> DefinedNumericVariable;
> +  std::optional<NumericVariable *> DefinedNumericVariable;
>    Expected<std::unique_ptr<Expression>> ExpressionPointer =
>        P.parseNumericSubstitutionBlock(LocalNumVar1Ref,
> DefinedNumericVariable,
>                                        /*IsLegacyLineExpr=*/false, LineNumber,
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> bin/mailman/listinfo/llvm-commits__;!!JmoZiZGBv3RvKRSx!-
> 3MGJ3moHIlSrHaTGNWpImARD69Bqt_7EtrAA6dZ_qnC-7ene0pXMGBxC8AKJf1-
> vqTcsIiAhkXyx-L1hCSwBFhnIV5I$


More information about the llvm-commits mailing list