mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Backed out changeset 02e6a50741a9 (bug 1153348) to hopefully fix the static bustage CLOSED TREE
This commit is contained in:
parent
10b0765a42
commit
638b28b8e0
@ -84,11 +84,6 @@ private:
|
|||||||
virtual void run(const MatchFinder::MatchResult &Result);
|
virtual void run(const MatchFinder::MatchResult &Result);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExplicitOperatorBoolChecker : public MatchFinder::MatchCallback {
|
|
||||||
public:
|
|
||||||
virtual void run(const MatchFinder::MatchResult &Result);
|
|
||||||
};
|
|
||||||
|
|
||||||
ScopeChecker stackClassChecker;
|
ScopeChecker stackClassChecker;
|
||||||
ScopeChecker globalClassChecker;
|
ScopeChecker globalClassChecker;
|
||||||
NonHeapClassChecker nonheapClassChecker;
|
NonHeapClassChecker nonheapClassChecker;
|
||||||
@ -97,17 +92,16 @@ private:
|
|||||||
NaNExprChecker nanExprChecker;
|
NaNExprChecker nanExprChecker;
|
||||||
NoAddRefReleaseOnReturnChecker noAddRefReleaseOnReturnChecker;
|
NoAddRefReleaseOnReturnChecker noAddRefReleaseOnReturnChecker;
|
||||||
RefCountedInsideLambdaChecker refCountedInsideLambdaChecker;
|
RefCountedInsideLambdaChecker refCountedInsideLambdaChecker;
|
||||||
ExplicitOperatorBoolChecker explicitOperatorBoolChecker;
|
|
||||||
MatchFinder astMatcher;
|
MatchFinder astMatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string getDeclarationNamespace(const Decl *decl) {
|
bool isInIgnoredNamespace(const Decl *decl) {
|
||||||
const DeclContext *DC = decl->getDeclContext()->getEnclosingNamespaceContext();
|
const DeclContext *DC = decl->getDeclContext()->getEnclosingNamespaceContext();
|
||||||
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
|
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
|
||||||
if (!ND) {
|
if (!ND) {
|
||||||
return "";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (const DeclContext *ParentDC = ND->getParent()) {
|
while (const DeclContext *ParentDC = ND->getParent()) {
|
||||||
@ -118,15 +112,8 @@ std::string getDeclarationNamespace(const Decl *decl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto& name = ND->getName();
|
const auto& name = ND->getName();
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInIgnoredNamespaceForImplicitCtor(const Decl *decl) {
|
|
||||||
std::string name = getDeclarationNamespace(decl);
|
|
||||||
if (name == "") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// namespace std and icu are ignored for now
|
||||||
return name == "std" || // standard C++ lib
|
return name == "std" || // standard C++ lib
|
||||||
name == "__gnu_cxx" || // gnu C++ lib
|
name == "__gnu_cxx" || // gnu C++ lib
|
||||||
name == "boost" || // boost
|
name == "boost" || // boost
|
||||||
@ -142,19 +129,7 @@ bool isInIgnoredNamespaceForImplicitCtor(const Decl *decl) {
|
|||||||
name == "testing"; // gtest
|
name == "testing"; // gtest
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInIgnoredNamespaceForImplicitConversion(const Decl *decl) {
|
bool isIgnoredPath(const Decl *decl) {
|
||||||
std::string name = getDeclarationNamespace(decl);
|
|
||||||
if (name == "") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return name == "std" || // standard C++ lib
|
|
||||||
name == "__gnu_cxx" || // gnu C++ lib
|
|
||||||
name == "google_breakpad" || // breakpad
|
|
||||||
name == "testing"; // gtest
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isIgnoredPathForImplicitCtor(const Decl *decl) {
|
|
||||||
decl = decl->getCanonicalDecl();
|
decl = decl->getCanonicalDecl();
|
||||||
SourceLocation Loc = decl->getLocation();
|
SourceLocation Loc = decl->getLocation();
|
||||||
const SourceManager &SM = decl->getASTContext().getSourceManager();
|
const SourceManager &SM = decl->getASTContext().getSourceManager();
|
||||||
@ -175,30 +150,9 @@ bool isIgnoredPathForImplicitCtor(const Decl *decl) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isIgnoredPathForImplicitConversion(const Decl *decl) {
|
bool isInterestingDecl(const Decl *decl) {
|
||||||
decl = decl->getCanonicalDecl();
|
return !isInIgnoredNamespace(decl) &&
|
||||||
SourceLocation Loc = decl->getLocation();
|
!isIgnoredPath(decl);
|
||||||
const SourceManager &SM = decl->getASTContext().getSourceManager();
|
|
||||||
SmallString<1024> FileName = SM.getFilename(Loc);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInterestingDeclForImplicitCtor(const Decl *decl) {
|
|
||||||
return !isInIgnoredNamespaceForImplicitCtor(decl) &&
|
|
||||||
!isIgnoredPathForImplicitCtor(decl);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInterestingDeclForImplicitConversion(const Decl *decl) {
|
|
||||||
return !isInIgnoredNamespaceForImplicitConversion(decl) &&
|
|
||||||
!isIgnoredPathForImplicitConversion(decl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -278,7 +232,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->isAbstract() && isInterestingDeclForImplicitCtor(d)) {
|
if (!d->isAbstract() && isInterestingDecl(d)) {
|
||||||
for (CXXRecordDecl::ctor_iterator ctor = d->ctor_begin(),
|
for (CXXRecordDecl::ctor_iterator ctor = d->ctor_begin(),
|
||||||
e = d->ctor_end(); ctor != e; ++ctor) {
|
e = d->ctor_end(); ctor != e; ++ctor) {
|
||||||
// Ignore non-converting ctors
|
// Ignore non-converting ctors
|
||||||
@ -462,16 +416,6 @@ bool isClassRefCounted(QualType T) {
|
|||||||
return clazz ? isClassRefCounted(clazz) : RegularClass;
|
return clazz ? isClassRefCounted(clazz) : RegularClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
bool IsInSystemHeader(const ASTContext &AC, const T &D) {
|
|
||||||
auto &SourceManager = AC.getSourceManager();
|
|
||||||
auto ExpansionLoc = SourceManager.getExpansionLoc(D.getLocStart());
|
|
||||||
if (ExpansionLoc.isInvalid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return SourceManager.isInSystemHeader(ExpansionLoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
@ -571,7 +515,12 @@ AST_MATCHER(QualType, isFloat) {
|
|||||||
/// isExpansionInSystemHeader in newer clangs, but modified in order to work
|
/// isExpansionInSystemHeader in newer clangs, but modified in order to work
|
||||||
/// with old clangs that we use on infra.
|
/// with old clangs that we use on infra.
|
||||||
AST_MATCHER(BinaryOperator, isInSystemHeader) {
|
AST_MATCHER(BinaryOperator, isInSystemHeader) {
|
||||||
return IsInSystemHeader(Finder->getASTContext(), Node);
|
auto &SourceManager = Finder->getASTContext().getSourceManager();
|
||||||
|
auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getLocStart());
|
||||||
|
if (ExpansionLoc.isInvalid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return SourceManager.isInSystemHeader(ExpansionLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This matcher will match locations in SkScalar.h. This header contains a
|
/// This matcher will match locations in SkScalar.h. This header contains a
|
||||||
@ -700,13 +649,6 @@ DiagnosticsMatcher::DiagnosticsMatcher()
|
|||||||
hasDescendant(declRefExpr(hasType(pointerType(pointee(isRefCounted())))).bind("node"))
|
hasDescendant(declRefExpr(hasType(pointerType(pointee(isRefCounted())))).bind("node"))
|
||||||
),
|
),
|
||||||
&refCountedInsideLambdaChecker);
|
&refCountedInsideLambdaChecker);
|
||||||
|
|
||||||
// Older clang versions such as the ones used on the infra recognize these
|
|
||||||
// conversions as 'operator _Bool', but newer clang versions recognize these
|
|
||||||
// as 'operator bool'.
|
|
||||||
astMatcher.addMatcher(methodDecl(anyOf(hasName("operator bool"),
|
|
||||||
hasName("operator _Bool"))).bind("node"),
|
|
||||||
&explicitOperatorBoolChecker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticsMatcher::ScopeChecker::run(
|
void DiagnosticsMatcher::ScopeChecker::run(
|
||||||
@ -919,25 +861,6 @@ void DiagnosticsMatcher::RefCountedInsideLambdaChecker::run(
|
|||||||
Diag.Report(node->getLocStart(), noteID);
|
Diag.Report(node->getLocStart(), noteID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticsMatcher::ExplicitOperatorBoolChecker::run(
|
|
||||||
const MatchFinder::MatchResult &Result) {
|
|
||||||
DiagnosticsEngine &Diag = Result.Context->getDiagnostics();
|
|
||||||
unsigned errorID = Diag.getDiagnosticIDs()->getCustomDiagID(
|
|
||||||
DiagnosticIDs::Error, "bad implicit conversion operator for %0");
|
|
||||||
unsigned noteID = Diag.getDiagnosticIDs()->getCustomDiagID(
|
|
||||||
DiagnosticIDs::Note, "consider adding the explicit keyword to %0");
|
|
||||||
const CXXConversionDecl *method = Result.Nodes.getNodeAs<CXXConversionDecl>("node");
|
|
||||||
const CXXRecordDecl *clazz = method->getParent();
|
|
||||||
|
|
||||||
if (!method->isExplicitSpecified() &&
|
|
||||||
!MozChecker::hasCustomAnnotation(method, "moz_implicit") &&
|
|
||||||
!IsInSystemHeader(method->getASTContext(), *method) &&
|
|
||||||
isInterestingDeclForImplicitConversion(method)) {
|
|
||||||
Diag.Report(method->getLocStart(), errorID) << clazz;
|
|
||||||
Diag.Report(method->getLocStart(), noteID) << "'operator bool'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MozCheckAction : public PluginASTAction {
|
class MozCheckAction : public PluginASTAction {
|
||||||
public:
|
public:
|
||||||
ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override {
|
ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override {
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
#define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
|
|
||||||
|
|
||||||
struct Bad {
|
|
||||||
operator bool(); // expected-error {{bad implicit conversion operator for 'Bad'}} expected-note {{consider adding the explicit keyword to 'operator bool'}}
|
|
||||||
};
|
|
||||||
struct Good {
|
|
||||||
explicit operator bool();
|
|
||||||
};
|
|
||||||
struct Okay {
|
|
||||||
MOZ_IMPLICIT operator bool();
|
|
||||||
};
|
|
@ -7,7 +7,6 @@
|
|||||||
SOURCES += [
|
SOURCES += [
|
||||||
'TestBadImplicitConversionCtor.cpp',
|
'TestBadImplicitConversionCtor.cpp',
|
||||||
'TestCustomHeap.cpp',
|
'TestCustomHeap.cpp',
|
||||||
'TestExplicitOperatorBool.cpp',
|
|
||||||
'TestGlobalClass.cpp',
|
'TestGlobalClass.cpp',
|
||||||
'TestMustOverride.cpp',
|
'TestMustOverride.cpp',
|
||||||
'TestNANTestingExpr.cpp',
|
'TestNANTestingExpr.cpp',
|
||||||
|
@ -305,7 +305,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Boolean conversion operator so people can use this in boolean tests
|
// Boolean conversion operator so people can use this in boolean tests
|
||||||
explicit operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
return GetISupports();
|
return GetISupports();
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ protected:
|
|||||||
void SetOuter(HTMLMediaElement* outer) { mOuter = outer; }
|
void SetOuter(HTMLMediaElement* outer) { mOuter = outer; }
|
||||||
void SetCanPlay(bool aCanPlay);
|
void SetCanPlay(bool aCanPlay);
|
||||||
|
|
||||||
MOZ_IMPLICIT operator bool() const { return mValue; }
|
operator bool() const { return mValue; }
|
||||||
|
|
||||||
WakeLockBoolWrapper& operator=(bool val);
|
WakeLockBoolWrapper& operator=(bool val);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_IMPLICIT operator bool() const { return mHeld; }
|
operator bool() const { return mHeld; }
|
||||||
|
|
||||||
SelfReference(const SelfReference& aOther) = delete;
|
SelfReference(const SelfReference& aOther) = delete;
|
||||||
void operator=(const SelfReference& aOther) = delete;
|
void operator=(const SelfReference& aOther) = delete;
|
||||||
|
@ -1167,7 +1167,7 @@ public:
|
|||||||
if (plugin)
|
if (plugin)
|
||||||
mLibrary = plugin->GetLibrary();
|
mLibrary = plugin->GetLibrary();
|
||||||
}
|
}
|
||||||
explicit operator bool() { return !!mLibrary; }
|
operator bool() { return !!mLibrary; }
|
||||||
PluginLibrary* operator->() { return mLibrary; }
|
PluginLibrary* operator->() { return mLibrary; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -277,7 +277,7 @@ public:
|
|||||||
return mActor;
|
return mActor;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool()
|
operator bool()
|
||||||
{
|
{
|
||||||
return !!mActor;
|
return !!mActor;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class udev_lib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool() {
|
operator bool() {
|
||||||
return udev;
|
return udev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns whether the buffer is empty. */
|
/* Returns whether the buffer is empty. */
|
||||||
explicit operator bool() { return mLength; }
|
operator bool() { return mLength; }
|
||||||
|
|
||||||
/* Returns the memory location of the buffer. */
|
/* Returns the memory location of the buffer. */
|
||||||
const char* get() { return mBuf; }
|
const char* get() { return mBuf; }
|
||||||
|
@ -742,7 +742,7 @@ public:
|
|||||||
explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {}
|
explicit MOZ_CONSTEXPR Atomic(bool aInit) : Base(aInit) {}
|
||||||
|
|
||||||
// We provide boolean wrappers for the underlying AtomicBase methods.
|
// We provide boolean wrappers for the underlying AtomicBase methods.
|
||||||
MOZ_IMPLICIT operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
return Base::Intrinsics::load(Base::mValue);
|
return Base::Intrinsics::load(Base::mValue);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
return mPtr;
|
return mPtr;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ public:
|
|||||||
return mLength;
|
return mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool() { return !!mBuf; }
|
operator bool() { return !!mBuf; }
|
||||||
private:
|
private:
|
||||||
template <size_t Size2>
|
template <size_t Size2>
|
||||||
friend class Buffer;
|
friend class Buffer;
|
||||||
|
@ -90,9 +90,9 @@ public:
|
|||||||
* or not.
|
* or not.
|
||||||
*/
|
*/
|
||||||
#if defined(MOZILLA_XPCOMRT_API)
|
#if defined(MOZILLA_XPCOMRT_API)
|
||||||
explicit operator bool() const { return mBaseFile; }
|
operator bool() const { return mBaseFile; }
|
||||||
#else
|
#else
|
||||||
explicit operator bool() const { return mBaseFile || mBaseZip; }
|
operator bool() const { return mBaseFile || mBaseZip; }
|
||||||
#endif // defined(MOZILLA_XPCOMRT_API)
|
#endif // defined(MOZILLA_XPCOMRT_API)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +112,7 @@ struct nsTArrayFallibleResult
|
|||||||
// Note: allows implicit conversions from and to bool
|
// Note: allows implicit conversions from and to bool
|
||||||
MOZ_IMPLICIT nsTArrayFallibleResult(bool aResult) : mResult(aResult) {}
|
MOZ_IMPLICIT nsTArrayFallibleResult(bool aResult) : mResult(aResult) {}
|
||||||
|
|
||||||
MOZ_IMPLICIT operator bool() { return mResult; }
|
operator bool() { return mResult; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mResult;
|
bool mResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user