2016-12-18 00:35:53 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef Utils_h__
|
|
|
|
#define Utils_h__
|
|
|
|
|
2018-09-18 16:03:33 +03:00
|
|
|
#include "CustomAttributes.h"
|
2017-07-13 16:14:36 +03:00
|
|
|
#include "ThirdPartyPaths.h"
|
2020-02-27 15:53:54 +03:00
|
|
|
#include "ThreadAllows.h"
|
2016-12-18 00:35:53 +03:00
|
|
|
#include "plugin.h"
|
|
|
|
|
2019-10-28 09:54:25 +03:00
|
|
|
inline StringRef getFilename(const SourceManager &SM, SourceLocation Loc) {
|
|
|
|
// We use the presumed location to handle #line directives and such, so the
|
|
|
|
// plugin is friendly to icecc / sccache users.
|
|
|
|
auto PL = SM.getPresumedLoc(Loc);
|
|
|
|
if (PL.isValid()) {
|
|
|
|
return StringRef(PL.getFilename());
|
|
|
|
}
|
|
|
|
return SM.getFilename(Loc);
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:35:53 +03:00
|
|
|
// Check if the given expression contains an assignment expression.
|
|
|
|
// This can either take the form of a Binary Operator or a
|
|
|
|
// Overloaded Operator Call.
|
|
|
|
inline bool hasSideEffectAssignment(const Expr *Expression) {
|
|
|
|
if (auto OpCallExpr = dyn_cast_or_null<CXXOperatorCallExpr>(Expression)) {
|
|
|
|
auto BinOp = OpCallExpr->getOperator();
|
|
|
|
if (BinOp == OO_Equal || (BinOp >= OO_PlusEqual && BinOp <= OO_PipeEqual)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (auto BinOpExpr = dyn_cast_or_null<BinaryOperator>(Expression)) {
|
|
|
|
if (BinOpExpr->isAssignmentOp()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recurse to children.
|
|
|
|
for (const Stmt *SubStmt : Expression->children()) {
|
|
|
|
auto ChildExpr = dyn_cast_or_null<Expr>(SubStmt);
|
|
|
|
if (ChildExpr && hasSideEffectAssignment(ChildExpr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-13 16:14:36 +03:00
|
|
|
template <class T>
|
|
|
|
inline bool ASTIsInSystemHeader(const ASTContext &AC, const T &D) {
|
2016-12-18 00:35:53 +03:00
|
|
|
auto &SourceManager = AC.getSourceManager();
|
2018-11-03 16:41:36 +03:00
|
|
|
auto ExpansionLoc = SourceManager.getExpansionLoc(D.getBeginLoc());
|
2016-12-18 00:35:53 +03:00
|
|
|
if (ExpansionLoc.isInvalid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return SourceManager.isInSystemHeader(ExpansionLoc);
|
|
|
|
}
|
|
|
|
|
2017-07-13 16:14:36 +03:00
|
|
|
template <typename T> inline StringRef getNameChecked(const T &D) {
|
2016-12-18 00:35:53 +03:00
|
|
|
return D->getIdentifier() ? D->getName() : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A cached data of whether classes are refcounted or not.
|
|
|
|
typedef DenseMap<const CXXRecordDecl *, std::pair<const Decl *, bool>>
|
|
|
|
RefCountedMap;
|
|
|
|
extern RefCountedMap RefCountedClasses;
|
|
|
|
|
|
|
|
inline bool classHasAddRefRelease(const CXXRecordDecl *D) {
|
|
|
|
const RefCountedMap::iterator &It = RefCountedClasses.find(D);
|
|
|
|
if (It != RefCountedClasses.end()) {
|
|
|
|
return It->second.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SeenAddRef = false;
|
|
|
|
bool SeenRelease = false;
|
|
|
|
for (CXXRecordDecl::method_iterator Method = D->method_begin();
|
|
|
|
Method != D->method_end(); ++Method) {
|
|
|
|
const auto &Name = getNameChecked(Method);
|
|
|
|
if (Name == "AddRef") {
|
|
|
|
SeenAddRef = true;
|
|
|
|
} else if (Name == "Release") {
|
|
|
|
SeenRelease = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefCountedClasses[D] = std::make_pair(D, SeenAddRef && SeenRelease);
|
|
|
|
return SeenAddRef && SeenRelease;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isClassRefCounted(QualType T);
|
|
|
|
|
|
|
|
inline bool isClassRefCounted(const CXXRecordDecl *D) {
|
|
|
|
// Normalize so that D points to the definition if it exists.
|
|
|
|
if (!D->hasDefinition())
|
|
|
|
return false;
|
|
|
|
D = D->getDefinition();
|
|
|
|
// Base class: anyone with AddRef/Release is obviously a refcounted class.
|
|
|
|
if (classHasAddRefRelease(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Look through all base cases to figure out if the parent is a refcounted
|
|
|
|
// class.
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator Base = D->bases_begin();
|
|
|
|
Base != D->bases_end(); ++Base) {
|
|
|
|
bool Super = isClassRefCounted(Base->getType());
|
|
|
|
if (Super) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isClassRefCounted(QualType T) {
|
|
|
|
while (const clang::ArrayType *ArrTy = T->getAsArrayTypeUnsafe())
|
|
|
|
T = ArrTy->getElementType();
|
|
|
|
CXXRecordDecl *Clazz = T->getAsCXXRecordDecl();
|
|
|
|
return Clazz ? isClassRefCounted(Clazz) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const FieldDecl *getClassRefCntMember(const CXXRecordDecl *D) {
|
|
|
|
for (RecordDecl::field_iterator Field = D->field_begin(), E = D->field_end();
|
|
|
|
Field != E; ++Field) {
|
|
|
|
if (getNameChecked(Field) == "mRefCnt") {
|
|
|
|
return *Field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool typeHasVTable(QualType T) {
|
|
|
|
while (const clang::ArrayType *ArrTy = T->getAsArrayTypeUnsafe())
|
|
|
|
T = ArrTy->getElementType();
|
|
|
|
CXXRecordDecl *Offender = T->getAsCXXRecordDecl();
|
|
|
|
return Offender && Offender->hasDefinition() && Offender->isDynamicClass();
|
|
|
|
}
|
|
|
|
|
2020-06-17 18:56:44 +03:00
|
|
|
inline StringRef getDeclarationNamespace(const Decl *Declaration) {
|
2016-12-18 00:35:53 +03:00
|
|
|
const DeclContext *DC =
|
|
|
|
Declaration->getDeclContext()->getEnclosingNamespaceContext();
|
|
|
|
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
|
|
|
|
if (!ND) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
while (const DeclContext *ParentDC = ND->getParent()) {
|
|
|
|
if (!isa<NamespaceDecl>(ParentDC)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ND = cast<NamespaceDecl>(ParentDC);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &Name = ND->getName();
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isInIgnoredNamespaceForImplicitCtor(const Decl *Declaration) {
|
2020-06-17 18:56:44 +03:00
|
|
|
StringRef Name = getDeclarationNamespace(Declaration);
|
2016-12-18 00:35:53 +03:00
|
|
|
if (Name == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name == "std" || // standard C++ lib
|
|
|
|
Name == "__gnu_cxx" || // gnu C++ lib
|
|
|
|
Name == "boost" || // boost
|
|
|
|
Name == "webrtc" || // upstream webrtc
|
|
|
|
Name == "rtc" || // upstream webrtc 'base' package
|
2020-06-17 18:56:44 +03:00
|
|
|
Name.startswith("icu_") || // icu
|
2016-12-18 00:35:53 +03:00
|
|
|
Name == "google" || // protobuf
|
|
|
|
Name == "google_breakpad" || // breakpad
|
|
|
|
Name == "soundtouch" || // libsoundtouch
|
|
|
|
Name == "stagefright" || // libstagefright
|
|
|
|
Name == "MacFileUtilities" || // MacFileUtilities
|
|
|
|
Name == "dwarf2reader" || // dwarf2reader
|
|
|
|
Name == "arm_ex_to_module" || // arm_ex_to_module
|
|
|
|
Name == "testing" || // gtest
|
2019-12-19 19:05:35 +03:00
|
|
|
Name == "Json" || // jsoncpp
|
2020-04-17 20:18:57 +03:00
|
|
|
Name == "rlbox" || // rlbox
|
|
|
|
Name == "v8"; // irregexp
|
2016-12-18 00:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isInIgnoredNamespaceForImplicitConversion(const Decl *Declaration) {
|
2020-06-17 18:56:44 +03:00
|
|
|
StringRef Name = getDeclarationNamespace(Declaration);
|
2016-12-18 00:35:53 +03:00
|
|
|
if (Name == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name == "std" || // standard C++ lib
|
|
|
|
Name == "__gnu_cxx" || // gnu C++ lib
|
|
|
|
Name == "google_breakpad" || // breakpad
|
2019-12-19 19:05:35 +03:00
|
|
|
Name == "testing" || // gtest
|
|
|
|
Name == "rlbox"; // rlbox
|
2016-12-18 00:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isIgnoredPathForImplicitConversion(const Decl *Declaration) {
|
|
|
|
Declaration = Declaration->getCanonicalDecl();
|
|
|
|
SourceLocation Loc = Declaration->getLocation();
|
|
|
|
const SourceManager &SM = Declaration->getASTContext().getSourceManager();
|
2019-10-28 09:54:25 +03:00
|
|
|
SmallString<1024> FileName = getFilename(SM, Loc);
|
2016-12-18 00:35:53 +03:00
|
|
|
llvm::sys::fs::make_absolute(FileName);
|
|
|
|
llvm::sys::path::reverse_iterator Begin = llvm::sys::path::rbegin(FileName),
|
|
|
|
End = llvm::sys::path::rend(FileName);
|
|
|
|
for (; Begin != End; ++Begin) {
|
|
|
|
if (Begin->compare_lower(StringRef("graphite2")) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Begin->compare_lower(StringRef("chromium")) == 0) {
|
|
|
|
// Ignore security/sandbox/chromium but not ipc/chromium.
|
|
|
|
++Begin;
|
|
|
|
return Begin != End && Begin->compare_lower(StringRef("sandbox")) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-13 16:14:36 +03:00
|
|
|
inline bool isIgnoredPathForSprintfLiteral(const CallExpr *Call,
|
|
|
|
const SourceManager &SM) {
|
2018-11-03 16:41:36 +03:00
|
|
|
SourceLocation Loc = Call->getBeginLoc();
|
2019-10-28 09:54:25 +03:00
|
|
|
SmallString<1024> FileName = getFilename(SM, Loc);
|
2016-12-18 00:35:53 +03:00
|
|
|
llvm::sys::fs::make_absolute(FileName);
|
|
|
|
llvm::sys::path::reverse_iterator Begin = llvm::sys::path::rbegin(FileName),
|
|
|
|
End = llvm::sys::path::rend(FileName);
|
|
|
|
for (; Begin != End; ++Begin) {
|
|
|
|
if (Begin->compare_lower(StringRef("angle")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("chromium")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("crashreporter")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("google-breakpad")) == 0 ||
|
2017-03-28 22:46:57 +03:00
|
|
|
Begin->compare_lower(StringRef("gflags")) == 0 ||
|
2016-12-18 00:35:53 +03:00
|
|
|
Begin->compare_lower(StringRef("harfbuzz")) == 0 ||
|
2017-11-01 21:47:59 +03:00
|
|
|
Begin->compare_lower(StringRef("icu")) == 0 ||
|
2017-04-20 00:41:03 +03:00
|
|
|
Begin->compare_lower(StringRef("jsoncpp")) == 0 ||
|
2016-12-18 00:35:53 +03:00
|
|
|
Begin->compare_lower(StringRef("libstagefright")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("mtransport")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("protobuf")) == 0 ||
|
|
|
|
Begin->compare_lower(StringRef("skia")) == 0 ||
|
2017-01-08 01:20:25 +03:00
|
|
|
Begin->compare_lower(StringRef("sfntly")) == 0 ||
|
2016-12-18 00:35:53 +03:00
|
|
|
// Gtest uses snprintf as GTEST_SNPRINTF_ with sizeof
|
2018-11-28 22:31:21 +03:00
|
|
|
Begin->compare_lower(StringRef("testing")) == 0) {
|
2016-12-18 00:35:53 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Begin->compare_lower(StringRef("webrtc")) == 0) {
|
|
|
|
// Ignore trunk/webrtc, but not media/webrtc
|
|
|
|
++Begin;
|
|
|
|
return Begin != End && Begin->compare_lower(StringRef("trunk")) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isInterestingDeclForImplicitConversion(const Decl *Declaration) {
|
|
|
|
return !isInIgnoredNamespaceForImplicitConversion(Declaration) &&
|
|
|
|
!isIgnoredPathForImplicitConversion(Declaration);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isIgnoredExprForMustUse(const Expr *E) {
|
|
|
|
if (const CXXOperatorCallExpr *OpCall = dyn_cast<CXXOperatorCallExpr>(E)) {
|
|
|
|
switch (OpCall->getOperator()) {
|
|
|
|
case OO_Equal:
|
|
|
|
case OO_PlusEqual:
|
|
|
|
case OO_MinusEqual:
|
|
|
|
case OO_StarEqual:
|
|
|
|
case OO_SlashEqual:
|
|
|
|
case OO_PercentEqual:
|
|
|
|
case OO_CaretEqual:
|
|
|
|
case OO_AmpEqual:
|
|
|
|
case OO_PipeEqual:
|
|
|
|
case OO_LessLessEqual:
|
|
|
|
case OO_GreaterGreaterEqual:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const BinaryOperator *Op = dyn_cast<BinaryOperator>(E)) {
|
|
|
|
return Op->isAssignmentOp();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool typeIsRefPtr(QualType Q) {
|
|
|
|
CXXRecordDecl *D = Q->getAsCXXRecordDecl();
|
|
|
|
if (!D || !D->getIdentifier()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef name = D->getName();
|
|
|
|
if (name == "RefPtr" || name == "nsCOMPtr") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The method defined in clang for ignoring implicit nodes doesn't work with
|
|
|
|
// some AST trees. To get around this, we define our own implementation of
|
|
|
|
// IgnoreTrivials.
|
2019-03-21 14:50:55 +03:00
|
|
|
inline const Stmt *MaybeSkipOneTrivial(const Stmt *s) {
|
2020-02-17 21:30:50 +03:00
|
|
|
if (!s) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) {
|
|
|
|
return ewc->getSubExpr();
|
|
|
|
}
|
|
|
|
if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) {
|
|
|
|
// With clang 10 and up `getTemporary` has been replaced with the more
|
|
|
|
// versatile `getSubExpr`.
|
2019-11-21 17:07:44 +03:00
|
|
|
#if CLANG_VERSION_FULL >= 1000
|
2020-02-17 21:30:50 +03:00
|
|
|
return mte->getSubExpr();
|
2019-11-21 17:07:44 +03:00
|
|
|
#else
|
2020-02-17 21:30:50 +03:00
|
|
|
return mte->GetTemporaryExpr();
|
2019-11-21 17:07:44 +03:00
|
|
|
#endif
|
2020-02-17 21:30:50 +03:00
|
|
|
}
|
|
|
|
if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) {
|
|
|
|
return bte->getSubExpr();
|
|
|
|
}
|
|
|
|
if (auto *ce = dyn_cast<CastExpr>(s)) {
|
|
|
|
s = ce->getSubExpr();
|
|
|
|
}
|
|
|
|
if (auto *pe = dyn_cast<ParenExpr>(s)) {
|
|
|
|
s = pe->getSubExpr();
|
|
|
|
}
|
|
|
|
// Not a trivial.
|
|
|
|
return s;
|
2019-03-21 14:50:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const Stmt *IgnoreTrivials(const Stmt *s) {
|
|
|
|
while (true) {
|
2020-02-17 21:30:50 +03:00
|
|
|
const Stmt *newS = MaybeSkipOneTrivial(s);
|
2019-03-21 14:50:55 +03:00
|
|
|
if (newS == s) {
|
|
|
|
return newS;
|
|
|
|
}
|
|
|
|
s = newS;
|
2016-12-18 00:35:53 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 14:50:55 +03:00
|
|
|
// Unreachable
|
|
|
|
return nullptr;
|
2016-12-18 00:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const Expr *IgnoreTrivials(const Expr *e) {
|
2017-08-14 12:40:36 +03:00
|
|
|
return cast_or_null<Expr>(IgnoreTrivials(static_cast<const Stmt *>(e)));
|
2016-12-18 00:35:53 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 14:50:55 +03:00
|
|
|
// Returns the input if the input is not a trivial.
|
|
|
|
inline const Expr *MaybeSkipOneTrivial(const Expr *e) {
|
|
|
|
return cast_or_null<Expr>(MaybeSkipOneTrivial(static_cast<const Stmt *>(e)));
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:35:53 +03:00
|
|
|
const FieldDecl *getBaseRefCntMember(QualType T);
|
|
|
|
|
|
|
|
inline const FieldDecl *getBaseRefCntMember(const CXXRecordDecl *D) {
|
|
|
|
const FieldDecl *RefCntMember = getClassRefCntMember(D);
|
|
|
|
if (RefCntMember && isClassRefCounted(D)) {
|
|
|
|
return RefCntMember;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator Base = D->bases_begin(),
|
|
|
|
E = D->bases_end();
|
|
|
|
Base != E; ++Base) {
|
|
|
|
RefCntMember = getBaseRefCntMember(Base->getType());
|
|
|
|
if (RefCntMember) {
|
|
|
|
return RefCntMember;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const FieldDecl *getBaseRefCntMember(QualType T) {
|
|
|
|
while (const clang::ArrayType *ArrTy = T->getAsArrayTypeUnsafe())
|
|
|
|
T = ArrTy->getElementType();
|
|
|
|
CXXRecordDecl *Clazz = T->getAsCXXRecordDecl();
|
|
|
|
return Clazz ? getBaseRefCntMember(Clazz) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isPlacementNew(const CXXNewExpr *Expression) {
|
|
|
|
// Regular new expressions aren't placement new
|
|
|
|
if (Expression->getNumPlacementArgs() == 0)
|
|
|
|
return false;
|
|
|
|
const FunctionDecl *Declaration = Expression->getOperatorNew();
|
2018-09-18 16:03:33 +03:00
|
|
|
if (Declaration && hasCustomAttribute<moz_heap_allocator>(Declaration)) {
|
2016-12-18 00:35:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-28 09:54:25 +03:00
|
|
|
extern DenseMap<StringRef, bool> InThirdPartyPathCache;
|
2018-10-26 00:21:36 +03:00
|
|
|
|
2017-04-27 19:44:46 +03:00
|
|
|
inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
|
2019-10-28 09:54:25 +03:00
|
|
|
StringRef OriginalFileName = getFilename(SM, Loc);
|
|
|
|
auto pair = InThirdPartyPathCache.find(OriginalFileName);
|
2018-10-26 00:21:36 +03:00
|
|
|
if (pair != InThirdPartyPathCache.end()) {
|
|
|
|
return pair->second;
|
|
|
|
}
|
|
|
|
|
2019-10-28 09:54:25 +03:00
|
|
|
SmallString<1024> FileName = OriginalFileName;
|
2018-11-13 11:22:25 +03:00
|
|
|
llvm::sys::fs::make_absolute(FileName);
|
2017-04-27 19:44:46 +03:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < MOZ_THIRD_PARTY_PATHS_COUNT; ++i) {
|
|
|
|
auto PathB = sys::path::begin(FileName);
|
|
|
|
auto PathE = sys::path::end(FileName);
|
|
|
|
|
|
|
|
auto ThirdPartyB = sys::path::begin(MOZ_THIRD_PARTY_PATHS[i]);
|
|
|
|
auto ThirdPartyE = sys::path::end(MOZ_THIRD_PARTY_PATHS[i]);
|
|
|
|
|
|
|
|
for (; PathB != PathE; ++PathB) {
|
|
|
|
// Perform an inner loop to compare path segments, checking if the current
|
|
|
|
// segment is the start of the current third party path.
|
|
|
|
auto IPathB = PathB;
|
|
|
|
auto IThirdPartyB = ThirdPartyB;
|
|
|
|
for (; IPathB != PathE && IThirdPartyB != ThirdPartyE;
|
|
|
|
++IPathB, ++IThirdPartyB) {
|
|
|
|
if (IPathB->compare_lower(*IThirdPartyB) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found a match!
|
|
|
|
if (IThirdPartyB == ThirdPartyE) {
|
2019-10-28 09:54:25 +03:00
|
|
|
InThirdPartyPathCache.insert(std::make_pair(OriginalFileName, true));
|
2017-04-27 19:44:46 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 09:54:25 +03:00
|
|
|
InThirdPartyPathCache.insert(std::make_pair(OriginalFileName, false));
|
2017-04-27 19:44:46 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 17:14:21 +03:00
|
|
|
inline bool inThirdPartyPath(const Decl *D, ASTContext *context) {
|
2017-04-27 19:44:46 +03:00
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
SourceLocation Loc = D->getLocation();
|
2017-07-05 17:14:21 +03:00
|
|
|
const SourceManager &SM = context->getSourceManager();
|
2017-04-27 19:44:46 +03:00
|
|
|
|
|
|
|
return inThirdPartyPath(Loc, SM);
|
|
|
|
}
|
|
|
|
|
2017-10-20 20:11:50 +03:00
|
|
|
inline CXXRecordDecl *getNonTemplateSpecializedCXXRecordDecl(QualType Q) {
|
2017-08-08 19:48:53 +03:00
|
|
|
auto *D = Q->getAsCXXRecordDecl();
|
|
|
|
|
|
|
|
if (!D) {
|
|
|
|
auto TemplateQ = Q->getAs<TemplateSpecializationType>();
|
|
|
|
if (!TemplateQ) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto TemplateDecl = TemplateQ->getTemplateName().getAsTemplateDecl();
|
|
|
|
if (!TemplateDecl) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
D = dyn_cast_or_null<CXXRecordDecl>(TemplateDecl->getTemplatedDecl());
|
|
|
|
if (!D) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2017-07-05 17:14:21 +03:00
|
|
|
inline bool inThirdPartyPath(const Decl *D) {
|
|
|
|
return inThirdPartyPath(D, &D->getASTContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool inThirdPartyPath(const Stmt *S, ASTContext *context) {
|
2018-11-03 16:41:36 +03:00
|
|
|
SourceLocation Loc = S->getBeginLoc();
|
2017-07-05 17:14:21 +03:00
|
|
|
const SourceManager &SM = context->getSourceManager();
|
2018-03-07 15:36:44 +03:00
|
|
|
auto ExpansionLoc = SM.getExpansionLoc(Loc);
|
|
|
|
if (ExpansionLoc.isInvalid()) {
|
|
|
|
return inThirdPartyPath(Loc, SM);
|
|
|
|
}
|
|
|
|
return inThirdPartyPath(ExpansionLoc, SM);
|
2017-07-05 17:14:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Polyfill for CXXOperatorCallExpr::isInfixBinaryOp()
|
2017-10-20 20:11:50 +03:00
|
|
|
inline bool isInfixBinaryOp(const CXXOperatorCallExpr *OpCall) {
|
2017-07-05 17:14:21 +03:00
|
|
|
#if CLANG_VERSION_FULL >= 400
|
|
|
|
return OpCall->isInfixBinaryOp();
|
|
|
|
#else
|
|
|
|
// Taken from clang source.
|
|
|
|
if (OpCall->getNumArgs() != 2)
|
2017-10-20 20:11:50 +03:00
|
|
|
return false;
|
2017-07-05 17:14:21 +03:00
|
|
|
|
|
|
|
switch (OpCall->getOperator()) {
|
2017-10-20 20:11:50 +03:00
|
|
|
case OO_Call:
|
|
|
|
case OO_Subscript:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
2017-07-05 17:14:21 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:35:53 +03:00
|
|
|
#endif
|