Index: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h @@ -82,7 +82,7 @@ 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 QualifiedName; + std::vector QualifiedName; unsigned RequiredArgs; public: @@ -90,29 +90,18 @@ /// 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 QualifiedName, + CallDescription(ArrayRef 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({FuncName}), NoArgRequirement) { - } - /// Get the name of the function that this object matches. StringRef getFunctionName() const { return QualifiedName.back(); } }; Index: lib/StaticAnalyzer/Core/CallEvent.cpp =================================================================== --- lib/StaticAnalyzer/Core/CallEvent.cpp +++ lib/StaticAnalyzer/Core/CallEvent.cpp @@ -371,23 +371,26 @@ // accuracy. if (CD.QualifiedName.size() > 1 && D) { const DeclContext *Ctx = D->getDeclContext(); - std::vector 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(Ctx); Ctx = Ctx->getParent()) { + if (NumUnmatched == 0) + break; + if (const auto *ND = dyn_cast(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(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; }