diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp b/contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp index 661f7b999f2b..30cbd257b65e 100644 --- a/contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp +++ b/contrib/llvm-project/clang/lib/Analysis/CalledOnceCheck.cpp @@ -28,7 +28,6 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/BitmaskEnum.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" @@ -38,6 +37,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include <memory> +#include <optional> using namespace clang; @@ -163,7 +163,7 @@ public: NotVisited = 0x8, /* 1000 */ // We already reported a violation and stopped tracking calls for this // parameter. - Reported = 0x15, /* 1111 */ + Reported = 0xF, /* 1111 */ LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Reported) }; @@ -319,7 +319,7 @@ public: // We care about logical not only if we care about comparisons. if (!ShouldRetrieveFromComparisons) return nullptr; - LLVM_FALLTHROUGH; + [[fallthrough]]; // Function pointer/references can be dereferenced before a call. // That doesn't make it, however, any different from a regular call. // For this reason, dereference operation is a "no-op". @@ -494,7 +494,7 @@ struct Clarification { /// of basic blocks. class NotCalledClarifier : public ConstStmtVisitor<NotCalledClarifier, - llvm::Optional<Clarification>> { + std::optional<Clarification>> { public: /// The main entrypoint for the class, the function that tries to find the /// clarification of how to explain which sub-path starts with a CFG edge @@ -508,24 +508,24 @@ public: /// results only for such cases. For this very reason, the parent basic /// block, Conditional, is named that way, so it is clear what kind of /// block is expected. - static llvm::Optional<Clarification> - clarify(const CFGBlock *Conditional, const CFGBlock *SuccWithoutCall) { + static std::optional<Clarification> clarify(const CFGBlock *Conditional, + const CFGBlock *SuccWithoutCall) { if (const Stmt *Terminator = Conditional->getTerminatorStmt()) { return NotCalledClarifier{Conditional, SuccWithoutCall}.Visit(Terminator); } - return llvm::None; + return std::nullopt; } - llvm::Optional<Clarification> VisitIfStmt(const IfStmt *If) { + std::optional<Clarification> VisitIfStmt(const IfStmt *If) { return VisitBranchingBlock(If, NeverCalledReason::IfThen); } - llvm::Optional<Clarification> + std::optional<Clarification> VisitAbstractConditionalOperator(const AbstractConditionalOperator *Ternary) { return VisitBranchingBlock(Ternary, NeverCalledReason::IfThen); } - llvm::Optional<Clarification> VisitSwitchStmt(const SwitchStmt *Switch) { + std::optional<Clarification> VisitSwitchStmt(const SwitchStmt *Switch) { const Stmt *CaseToBlame = SuccInQuestion->getLabel(); if (!CaseToBlame) { // If interesting basic block is not labeled, it means that this @@ -543,15 +543,15 @@ public: llvm_unreachable("Found unexpected switch structure"); } - llvm::Optional<Clarification> VisitForStmt(const ForStmt *For) { + std::optional<Clarification> VisitForStmt(const ForStmt *For) { return VisitBranchingBlock(For, NeverCalledReason::LoopEntered); } - llvm::Optional<Clarification> VisitWhileStmt(const WhileStmt *While) { + std::optional<Clarification> VisitWhileStmt(const WhileStmt *While) { return VisitBranchingBlock(While, NeverCalledReason::LoopEntered); } - llvm::Optional<Clarification> + std::optional<Clarification> VisitBranchingBlock(const Stmt *Terminator, NeverCalledReason DefaultReason) { assert(Parent->succ_size() == 2 && "Branching block should have exactly two successors"); @@ -561,12 +561,12 @@ public: return Clarification{ActualReason, Terminator}; } - llvm::Optional<Clarification> VisitBinaryOperator(const BinaryOperator *) { + std::optional<Clarification> VisitBinaryOperator(const BinaryOperator *) { // We don't want to report on short-curcuit logical operations. - return llvm::None; + return std::nullopt; } - llvm::Optional<Clarification> VisitStmt(const Stmt *Terminator) { + std::optional<Clarification> VisitStmt(const Stmt *Terminator) { // If we got here, we didn't have a visit function for more derived // classes of statement that this terminator actually belongs to. // @@ -753,7 +753,7 @@ private: // We use a backward dataflow propagation and for this reason we // should traverse basic blocks bottom-up. for (const CFGElement &Element : llvm::reverse(*BB)) { - if (Optional<CFGStmt> S = Element.getAs<CFGStmt>()) { + if (std::optional<CFGStmt> S = Element.getAs<CFGStmt>()) { check(S->getStmt()); } } @@ -880,8 +880,8 @@ private: template <class CallLikeExpr> void checkIndirectCall(const CallLikeExpr *CallOrMessage) { // CallExpr::arguments does not interact nicely with llvm::enumerate. - llvm::ArrayRef<const Expr *> Arguments = llvm::makeArrayRef( - CallOrMessage->getArgs(), CallOrMessage->getNumArgs()); + llvm::ArrayRef<const Expr *> Arguments = + llvm::ArrayRef(CallOrMessage->getArgs(), CallOrMessage->getNumArgs()); // Let's check if any of the call arguments is a point of interest. for (const auto &Argument : llvm::enumerate(Arguments)) { @@ -932,7 +932,8 @@ private: ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor(Index); // Escape overrides whatever error we think happened. - if (CurrentParamStatus.isErrorStatus()) { + if (CurrentParamStatus.isErrorStatus() && + CurrentParamStatus.getKind() != ParameterStatus::Kind::Reported) { CurrentParamStatus = ParameterStatus::Escaped; } } @@ -973,7 +974,7 @@ private: /// Return true if the given name has conventional suffixes. static bool hasConventionalSuffix(llvm::StringRef Name) { return llvm::any_of(CONVENTIONAL_SUFFIXES, [Name](llvm::StringRef Suffix) { - return Name.endswith(Suffix); + return Name.ends_with(Suffix); }); } @@ -997,10 +998,10 @@ private: /// Return true/false if 'swift_async' attribute states that the given /// parameter is conventionally called once. - /// Return llvm::None if the given declaration doesn't have 'swift_async' + /// Return std::nullopt if the given declaration doesn't have 'swift_async' /// attribute. - static llvm::Optional<bool> isConventionalSwiftAsync(const Decl *D, - unsigned ParamIndex) { + static std::optional<bool> isConventionalSwiftAsync(const Decl *D, + unsigned ParamIndex) { if (const SwiftAsyncAttr *A = D->getAttr<SwiftAsyncAttr>()) { if (A->getKind() == SwiftAsyncAttr::None) { return false; @@ -1008,7 +1009,7 @@ private: return A->getCompletionHandlerIndex().getASTIndex() == ParamIndex; } - return llvm::None; + return std::nullopt; } /// Return true if the specified selector represents init method. @@ -1065,7 +1066,7 @@ private: // 'swift_async' goes first and overrides anything else. if (auto ConventionalAsync = isConventionalSwiftAsync(Function, ParamIndex)) { - return ConventionalAsync.getValue(); + return *ConventionalAsync; } return shouldBeCalledOnce(Function->getParamDecl(ParamIndex)) || @@ -1082,7 +1083,7 @@ private: // 'swift_async' goes first and overrides anything else. if (auto ConventionalAsync = isConventionalSwiftAsync(Method, ParamIndex)) { - return ConventionalAsync.getValue(); + return *ConventionalAsync; } const ParmVarDecl *Parameter = Method->getParamDecl(ParamIndex); @@ -1157,8 +1158,8 @@ private: bool shouldBlockArgumentBeCalledOnce(const CallLikeExpr *CallOrMessage, const Stmt *BlockArgument) const { // CallExpr::arguments does not interact nicely with llvm::enumerate. - llvm::ArrayRef<const Expr *> Arguments = llvm::makeArrayRef( - CallOrMessage->getArgs(), CallOrMessage->getNumArgs()); + llvm::ArrayRef<const Expr *> Arguments = + llvm::ArrayRef(CallOrMessage->getArgs(), CallOrMessage->getNumArgs()); for (const auto &Argument : llvm::enumerate(Arguments)) { if (Argument.value() == BlockArgument) { @@ -1265,7 +1266,7 @@ private: llvm::reverse(*BB), // we should start with return statements, if we // have any, i.e. from the bottom of the block [&ReturnChildren](const CFGElement &Element) { - if (Optional<CFGStmt> S = Element.getAs<CFGStmt>()) { + if (std::optional<CFGStmt> S = Element.getAs<CFGStmt>()) { const Stmt *SuspiciousStmt = S->getStmt(); if (isa<ReturnStmt>(SuspiciousStmt)) { @@ -1635,19 +1636,19 @@ public: private: unsigned size() const { return TrackedParams.size(); } - llvm::Optional<unsigned> getIndexOfCallee(const CallExpr *Call) const { + std::optional<unsigned> getIndexOfCallee(const CallExpr *Call) const { return getIndexOfExpression(Call->getCallee()); } - llvm::Optional<unsigned> getIndexOfExpression(const Expr *E) const { + std::optional<unsigned> getIndexOfExpression(const Expr *E) const { if (const ParmVarDecl *Parameter = findReferencedParmVarDecl(E)) { return getIndex(*Parameter); } - return llvm::None; + return std::nullopt; } - llvm::Optional<unsigned> getIndex(const ParmVarDecl &Parameter) const { + std::optional<unsigned> getIndex(const ParmVarDecl &Parameter) const { // Expected number of parameters that we actually track is 1. // // Also, the maximum number of declared parameters could not be on a scale @@ -1662,7 +1663,7 @@ private: return It - TrackedParams.begin(); } - return llvm::None; + return std::nullopt; } const ParmVarDecl *getParameter(unsigned Index) const { |