diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-09-25 22:13:31 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-09-25 22:13:31 +0000 |
commit | 0b7fdca640f020f9b9de53401cc2c29b36748cf7 (patch) | |
tree | 0805d8ca95863d757b76cc3cb7ba0d520ff9621d | |
parent | 5c9b3b757623e6bea5b4929b2046a565ee2d11bc (diff) | |
download | bcm5719-llvm-0b7fdca640f020f9b9de53401cc2c29b36748cf7.tar.gz bcm5719-llvm-0b7fdca640f020f9b9de53401cc2c29b36748cf7.zip |
[analyzer] NFC: CallDescription: Improve array management.
Combine the two constructor overrides into a single ArrayRef constructor
to allow easier brace initializations and simplify how the respective field
is used internally.
Differential Revision: https://reviews.llvm.org/D51390
llvm-svn: 343037
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h | 23 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 17 |
2 files changed, 16 insertions, 24 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h index f8b2cf70646..4c50eafbde5 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h @@ -82,7 +82,7 @@ class CallDescription { mutable bool IsLookupDone = false; // The list of the qualified names used to identify the specified CallEvent, // e.g. "{a, b}" represent the qualified names, like "a::b". - std::vector<StringRef> QualifiedName; + std::vector<const char *> QualifiedName; unsigned RequiredArgs; public: @@ -90,29 +90,18 @@ public: /// Constructs a CallDescription object. /// - /// @param QualifiedName The list of the qualified names of the function that - /// will be matched. It does not require the user to provide the full list of - /// the qualified name. The more details provided, the more accurate the - /// matching. + /// @param QualifiedName The list of the name qualifiers of the function that + /// will be matched. The user is allowed to skip any of the qualifiers. + /// For example, {"std", "basic_string", "c_str"} would match both + /// std::basic_string<...>::c_str() and std::__1::basic_string<...>::c_str(). /// /// @param RequiredArgs The number of arguments that is expected to match a /// call. Omit this parameter to match every occurrence of call with a given /// name regardless the number of arguments. - CallDescription(std::vector<StringRef> QualifiedName, + CallDescription(ArrayRef<const char *> QualifiedName, unsigned RequiredArgs = NoArgRequirement) : QualifiedName(QualifiedName), RequiredArgs(RequiredArgs) {} - /// Constructs a CallDescription object. - /// - /// @param FuncName The name of the function that will be matched. - /// - /// @param RequiredArgs The number of arguments that is expected to match a - /// call. Omit this parameter to match every occurrence of call with a given - /// name regardless the number of arguments. - CallDescription(StringRef FuncName, unsigned RequiredArgs = NoArgRequirement) - : CallDescription(std::vector<StringRef>({FuncName}), NoArgRequirement) { - } - /// Get the name of the function that this object matches. StringRef getFunctionName() const { return QualifiedName.back(); } }; diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 3ba68d4cdd2..7b6a8d4d252 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -371,23 +371,26 @@ bool CallEvent::isCalled(const CallDescription &CD) const { // accuracy. if (CD.QualifiedName.size() > 1 && D) { const DeclContext *Ctx = D->getDeclContext(); - std::vector<StringRef> QualifiedName = CD.QualifiedName; - QualifiedName.pop_back(); + // See if we'll be able to match them all. + size_t NumUnmatched = CD.QualifiedName.size() - 1; for (; Ctx && isa<NamedDecl>(Ctx); Ctx = Ctx->getParent()) { + if (NumUnmatched == 0) + break; + if (const auto *ND = dyn_cast<NamespaceDecl>(Ctx)) { - if (!QualifiedName.empty() && ND->getName() == QualifiedName.back()) - QualifiedName.pop_back(); + if (ND->getName() == CD.QualifiedName[NumUnmatched - 1]) + --NumUnmatched; continue; } if (const auto *RD = dyn_cast<RecordDecl>(Ctx)) { - if (!QualifiedName.empty() && RD->getName() == QualifiedName.back()) - QualifiedName.pop_back(); + if (RD->getName() == CD.QualifiedName[NumUnmatched - 1]) + --NumUnmatched; continue; } } - if (!QualifiedName.empty()) + if (NumUnmatched > 0) return false; } |