From 22731dbd75a9c3dd89ec08e2e86d10343609f58c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 4 Dec 2022 20:31:05 -0800 Subject: [PATCH] [clang] Use std::nullopt instead of None in comments (NFC) This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 --- clang/include/clang/APINotes/Types.h | 3 ++- clang/include/clang/AST/CharUnits.h | 3 ++- clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 2 +- .../clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h | 2 +- clang/include/clang/Analysis/RetainSummaryManager.h | 4 ++-- clang/include/clang/Basic/DarwinSDKInfo.h | 2 +- clang/include/clang/Basic/TargetID.h | 6 +++--- clang/include/clang/Frontend/CommandLineSourceLoc.h | 4 ++-- .../clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h | 3 ++- clang/include/clang/Tooling/Syntax/Tokens.h | 2 +- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp | 4 ++-- clang/lib/Driver/ToolChains/Cuda.cpp | 2 +- clang/lib/Format/ContinuationIndenter.cpp | 6 +++--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 4 ++-- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 4 ++-- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp | 5 +++-- clang/lib/Tooling/Transformer/Parsing.cpp | 2 +- 17 files changed, 31 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/APINotes/Types.h b/clang/include/clang/APINotes/Types.h index f75ac2b..eb27ffc 100644 --- a/clang/include/clang/APINotes/Types.h +++ b/clang/include/clang/APINotes/Types.h @@ -215,7 +215,8 @@ public: /// Determine the default nullability for properties and methods of this /// class. /// - /// eturns the default nullability, if implied, or None if there is no + /// Returns the default nullability, if implied, or std::nullopt if there is + /// none. llvm::Optional getDefaultNullability() const { return HasDefaultNullability ? llvm::Optional( diff --git a/clang/include/clang/AST/CharUnits.h b/clang/include/clang/AST/CharUnits.h index 2705f24..cd3dab00 100644 --- a/clang/include/clang/AST/CharUnits.h +++ b/clang/include/clang/AST/CharUnits.h @@ -183,7 +183,8 @@ namespace clang { llvm::Align getAsAlign() const { return llvm::Align(Quantity); } /// getAsMaybeAlign - Returns Quantity as a valid llvm::Align or - /// llvm::None, Beware llvm::MaybeAlign assumes power of two 8-bit bytes. + /// std::nullopt, Beware llvm::MaybeAlign assumes power of two 8-bit + /// bytes. llvm::MaybeAlign getAsMaybeAlign() const { return llvm::MaybeAlign(Quantity); } diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index f5a34a0..9e2ad3c 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -536,7 +536,7 @@ public: /// Returns the \c TraversalKind respected by calls to `match()`, if any. /// /// Most matchers will not have a traversal kind set, instead relying on the - /// surrounding context. For those, \c llvm::None is returned. + /// surrounding context. For those, \c std::nullopt is returned. llvm::Optional getTraversalKind() const { return Implementation->TraversalKind(); } diff --git a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h index 633f0ac2..b5dd749 100644 --- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h +++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h @@ -135,7 +135,7 @@ struct TypeErasedDataflowAnalysisState { /// /// All predecessors of `Block` except those with loop back edges must have /// already been transferred. States in `BlockStates` that are set to -/// `llvm::None` represent basic blocks that are not evaluated yet. +/// `std::nullopt` represent basic blocks that are not evaluated yet. TypeErasedDataflowAnalysisState transferBlock( const ControlFlowContext &CFCtx, llvm::ArrayRef> BlockStates, diff --git a/clang/include/clang/Analysis/RetainSummaryManager.h b/clang/include/clang/Analysis/RetainSummaryManager.h index d9a0416..3171dc3 100644 --- a/clang/include/clang/Analysis/RetainSummaryManager.h +++ b/clang/include/clang/Analysis/RetainSummaryManager.h @@ -719,8 +719,8 @@ private: /// type for functions/methods) @c QT has any of the given attributes, /// provided they pass necessary validation checks AND tracking the given /// attribute is enabled. - /// Returns the object kind corresponding to the present attribute, or None, - /// if none of the specified attributes are present. + /// Returns the object kind corresponding to the present attribute, or + /// std::nullopt, if none of the specified attributes are present. /// Crashes if passed an attribute which is not explicitly handled. template Optional hasAnyEnabledAttrOf(const Decl *D, QualType QT); diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h b/clang/include/clang/Basic/DarwinSDKInfo.h index 8cc10df..eed7668 100644 --- a/clang/include/clang/Basic/DarwinSDKInfo.h +++ b/clang/include/clang/Basic/DarwinSDKInfo.h @@ -99,7 +99,7 @@ public: /// Returns the mapped key, or the appropriate Minimum / MaximumValue if /// they key is outside of the mapping bounds. If they key isn't mapped, but - /// within the minimum and maximum bounds, None is returned. + /// within the minimum and maximum bounds, std::nullopt is returned. std::optional map(const VersionTuple &Key, const VersionTuple &MinimumValue, std::optional MaximumValue) const; diff --git a/clang/include/clang/Basic/TargetID.h b/clang/include/clang/Basic/TargetID.h index b2d35d8..d7c05b2 100644 --- a/clang/include/clang/Basic/TargetID.h +++ b/clang/include/clang/Basic/TargetID.h @@ -31,9 +31,9 @@ llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch); /// Parse a target ID to get processor and feature map. -/// Returns canonicalized processor name or None if the target ID is invalid. -/// Returns target ID features in \p FeatureMap if it is not null pointer. -/// This function assumes \p OffloadArch is a valid target ID. +/// Returns canonicalized processor name or std::nullopt if the target ID is +/// invalid. Returns target ID features in \p FeatureMap if it is not null +/// pointer. This function assumes \p OffloadArch is a valid target ID. /// If the target ID contains feature+, map it to true. /// If the target ID contains feature-, map it to false. /// If the target ID does not contain a feature (default), do not map it. diff --git a/clang/include/clang/Frontend/CommandLineSourceLoc.h b/clang/include/clang/Frontend/CommandLineSourceLoc.h index 5177b8d..f511475 100644 --- a/clang/include/clang/Frontend/CommandLineSourceLoc.h +++ b/clang/include/clang/Frontend/CommandLineSourceLoc.h @@ -67,8 +67,8 @@ struct ParsedSourceRange { /// second element is the column. std::pair End; - /// Returns a parsed source range from a string or None if the string is - /// invalid. + /// Returns a parsed source range from a string or std::nullopt if the string + /// is invalid. /// /// These source string has the following format: /// diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h index e89a993..f7a39e7 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h @@ -67,7 +67,8 @@ Nullability getNullabilityAnnotation(QualType Type); /// Try to parse the value of a defined preprocessor macro. We can only parse /// simple expressions that consist of an optional minus sign token and then a -/// token for an integer. If we cannot parse the value then None is returned. +/// token for an integer. If we cannot parse the value then std::nullopt is +/// returned. llvm::Optional tryExpandAsInteger(StringRef Macro, const Preprocessor &PP); class OperatorKind { diff --git a/clang/include/clang/Tooling/Syntax/Tokens.h b/clang/include/clang/Tooling/Syntax/Tokens.h index ea2f143..37c3092 100644 --- a/clang/include/clang/Tooling/Syntax/Tokens.h +++ b/clang/include/clang/Tooling/Syntax/Tokens.h @@ -204,7 +204,7 @@ public: /// Returns the subrange of spelled tokens corresponding to AST node spanning /// \p Expanded. This is the text that should be replaced if a refactoring /// were to rewrite the node. If \p Expanded is empty, the returned value is - /// llvm::None. + /// std::nullopt. /// /// Will fail if the expanded tokens do not correspond to a sequence of /// spelled tokens. E.g. for the following example: diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp index 8f0df9e..9576287 100644 --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -210,7 +210,7 @@ struct AnalysisContext { /// /// All predecessors of `Block` except those with loop back edges must have /// already been transferred. States in `AC.BlockStates` that are set to -/// `llvm::None` represent basic blocks that are not evaluated yet. +/// `std::nullopt` represent basic blocks that are not evaluated yet. static TypeErasedDataflowAnalysisState computeBlockInputState(const CFGBlock &Block, AnalysisContext &AC) { llvm::DenseSet Preds; @@ -479,7 +479,7 @@ runTypeErasedDataflowAnalysis( Worklist.enqueueSuccessors(Block); } // FIXME: Consider evaluating unreachable basic blocks (those that have a - // state set to `llvm::None` at this point) to also analyze dead code. + // state set to `std::nullopt` at this point) to also analyze dead code. if (PostVisitCFG) { for (const CFGBlock *Block : CFCtx.getCFG()) { diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index f4bcb73..e72cecc 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -78,7 +78,7 @@ CudaVersion getCudaVersion(uint32_t raw_version) { CudaVersion parseCudaHFile(llvm::StringRef Input) { // Helper lambda which skips the words if the line starts with them or returns - // None otherwise. + // std::nullopt otherwise. auto StartsWithWords = [](llvm::StringRef Line, const SmallVector words) -> std::optional { diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 462ec3c..4e5672f 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -146,9 +146,9 @@ static bool opensProtoMessageField(const FormatToken &LessTok, (LessTok.Previous && LessTok.Previous->is(tok::equal)))); } -// Returns the delimiter of a raw string literal, or None if TokenText is not -// the text of a raw string literal. The delimiter could be the empty string. -// For example, the delimiter of R"deli(cont)deli" is deli. +// Returns the delimiter of a raw string literal, or std::nullopt if TokenText +// is not the text of a raw string literal. The delimiter could be the empty +// string. For example, the delimiter of R"deli(cont)deli" is deli. static llvm::Optional getRawStringDelimiter(StringRef TokenText) { if (TokenText.size() < 5 // The smallest raw string possible is 'R"()"'. || !TokenText.startswith("R\"") || !TokenText.endswith("\"")) { diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index efacde9..0eecebd 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -538,7 +538,7 @@ private: /// Dereferences fields up to a given recursion limit. /// Note that \p Vec is passed by value, leading to quadratic copying cost, /// but it's OK in practice since its length is limited to DEREFERENCE_LIMIT. - /// \return A chain fields leading to the region of interest or None. + /// \return A chain fields leading to the region of interest or std::nullopt. const Optional findRegionOfInterestInRecord(const RecordDecl *RD, ProgramStateRef State, const MemRegion *R, const RegionVector &Vec = {}, @@ -619,7 +619,7 @@ static bool potentiallyWritesIntoIvar(const Decl *Parent, /// Dereferences fields up to a given recursion limit. /// Note that \p Vec is passed by value, leading to quadratic copying cost, /// but it's OK in practice since its length is limited to DEREFERENCE_LIMIT. -/// \return A chain fields leading to the region of interest or None. +/// \return A chain fields leading to the region of interest or std::nullopt. const Optional NoStoreFuncVisitor::findRegionOfInterestInRecord( const RecordDecl *RD, ProgramStateRef State, const MemRegion *R, diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index b2eace8..5e8c93a 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -2671,8 +2671,8 @@ bool ExprEngine::hasMoreIteration(ProgramStateRef State, } /// Split the state on whether there are any more iterations left for this loop. -/// Returns a (HasMoreIteration, HasNoMoreIteration) pair, or None when the -/// acquisition of the loop condition value failed. +/// Returns a (HasMoreIteration, HasNoMoreIteration) pair, or std::nullopt when +/// the acquisition of the loop condition value failed. static Optional> assumeCondition(const Stmt *Condition, ExplodedNode *N) { ProgramStateRef State = N->getState(); diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp index 3e434f1..ca9bc52 100644 --- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp @@ -1164,7 +1164,8 @@ template /// Main generic intersect function. /// It intersects all of the given range sets. If some of the given arguments -/// don't hold a range set (nullptr or llvm::None), the function will skip them. +/// don't hold a range set (nullptr or std::nullopt), the function will skip +/// them. /// /// Available representations for the arguments are: /// * RangeSet @@ -1179,7 +1180,7 @@ template /// simply RangeSet, in other cases we have to back off to Optional. /// /// Please, prefer optional range sets to raw pointers. If the last argument is -/// a raw pointer and all previous arguments are None, it will cost one +/// a raw pointer and all previous arguments are std::nullopt, it will cost one /// additional check to convert RangeSet * into Optional. template [[nodiscard]] inline diff --git a/clang/lib/Tooling/Transformer/Parsing.cpp b/clang/lib/Tooling/Transformer/Parsing.cpp index 25bbf98..df0f62a 100644 --- a/clang/lib/Tooling/Transformer/Parsing.cpp +++ b/clang/lib/Tooling/Transformer/Parsing.cpp @@ -46,7 +46,7 @@ struct ParseState { }; // Represents an intermediate result returned by a parsing function. Functions -// that don't generate values should use `llvm::None` +// that don't generate values should use `std::nullopt` template struct ParseProgress { ParseState State; // Intermediate result generated by the Parser. -- 2.7.4