зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1591493 - Clang plugin should work with distributed builds. r=andi
sccache-dist / icecream preprocess the file and then send it to a builder. That means that the file contains #line directives or equivalents in order for diagnostics and such to work correctly. Unfortunately our clang-plugin build fails catastrophically if you include a third-party header, as it doesn't account for them. Use SourceManager::getPresumedLoc to get filenames, as it accounts for them, unlike just getFilename. Differential Revision: https://phabricator.services.mozilla.com/D50633 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3d9436817b
Коммит
ddabf6673b
|
@ -137,9 +137,8 @@ AST_MATCHER(BinaryOperator, isInWhitelistForNaNExpr) {
|
|||
const char *whitelist[] = {"SkScalar.h", "json_writer.cpp", "State.cpp"};
|
||||
|
||||
SourceLocation Loc = Node.getOperatorLoc();
|
||||
auto &SourceManager = Finder->getASTContext().getSourceManager();
|
||||
SmallString<1024> FileName = SourceManager.getFilename(Loc);
|
||||
|
||||
StringRef FileName =
|
||||
getFilename(Finder->getASTContext().getSourceManager(), Loc);
|
||||
for (auto itr = std::begin(whitelist); itr != std::end(whitelist); itr++) {
|
||||
if (llvm::sys::path::rbegin(FileName)->equals(*itr)) {
|
||||
return true;
|
||||
|
|
|
@ -24,4 +24,4 @@ public:
|
|||
static FrontendPluginRegistry::Add<MozCheckAction> X("moz-check",
|
||||
"check moz action");
|
||||
|
||||
DenseMap<unsigned, bool> InThirdPartyPathCache;
|
||||
DenseMap<StringRef, bool> InThirdPartyPathCache;
|
||||
|
|
|
@ -9,6 +9,16 @@
|
|||
#include "ThirdPartyPaths.h"
|
||||
#include "plugin.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Check if the given expression contains an assignment expression.
|
||||
// This can either take the form of a Binary Operator or a
|
||||
// Overloaded Operator Call.
|
||||
|
@ -181,7 +191,7 @@ inline bool isIgnoredPathForImplicitConversion(const Decl *Declaration) {
|
|||
Declaration = Declaration->getCanonicalDecl();
|
||||
SourceLocation Loc = Declaration->getLocation();
|
||||
const SourceManager &SM = Declaration->getASTContext().getSourceManager();
|
||||
SmallString<1024> FileName = SM.getFilename(Loc);
|
||||
SmallString<1024> FileName = getFilename(SM, Loc);
|
||||
llvm::sys::fs::make_absolute(FileName);
|
||||
llvm::sys::path::reverse_iterator Begin = llvm::sys::path::rbegin(FileName),
|
||||
End = llvm::sys::path::rend(FileName);
|
||||
|
@ -201,7 +211,7 @@ inline bool isIgnoredPathForImplicitConversion(const Decl *Declaration) {
|
|||
inline bool isIgnoredPathForSprintfLiteral(const CallExpr *Call,
|
||||
const SourceManager &SM) {
|
||||
SourceLocation Loc = Call->getBeginLoc();
|
||||
SmallString<1024> FileName = SM.getFilename(Loc);
|
||||
SmallString<1024> FileName = getFilename(SM, Loc);
|
||||
llvm::sys::fs::make_absolute(FileName);
|
||||
llvm::sys::path::reverse_iterator Begin = llvm::sys::path::rbegin(FileName),
|
||||
End = llvm::sys::path::rend(FileName);
|
||||
|
@ -362,18 +372,16 @@ inline bool isPlacementNew(const CXXNewExpr *Expression) {
|
|||
return true;
|
||||
}
|
||||
|
||||
extern DenseMap<unsigned, bool> InThirdPartyPathCache;
|
||||
extern DenseMap<StringRef, bool> InThirdPartyPathCache;
|
||||
|
||||
inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
|
||||
Loc = SM.getFileLoc(Loc);
|
||||
|
||||
unsigned id = SM.getFileID(Loc).getHashValue();
|
||||
auto pair = InThirdPartyPathCache.find(id);
|
||||
StringRef OriginalFileName = getFilename(SM, Loc);
|
||||
auto pair = InThirdPartyPathCache.find(OriginalFileName);
|
||||
if (pair != InThirdPartyPathCache.end()) {
|
||||
return pair->second;
|
||||
}
|
||||
|
||||
SmallString<1024> FileName = SM.getFilename(Loc);
|
||||
SmallString<1024> FileName = OriginalFileName;
|
||||
llvm::sys::fs::make_absolute(FileName);
|
||||
|
||||
for (uint32_t i = 0; i < MOZ_THIRD_PARTY_PATHS_COUNT; ++i) {
|
||||
|
@ -397,13 +405,13 @@ inline bool inThirdPartyPath(SourceLocation Loc, const SourceManager &SM) {
|
|||
|
||||
// We found a match!
|
||||
if (IThirdPartyB == ThirdPartyE) {
|
||||
InThirdPartyPathCache.insert(std::make_pair(id, true));
|
||||
InThirdPartyPathCache.insert(std::make_pair(OriginalFileName, true));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InThirdPartyPathCache.insert(std::make_pair(id, false));
|
||||
InThirdPartyPathCache.insert(std::make_pair(OriginalFileName, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
#line 1 "tests/SkScalar.h"
|
||||
// This checks that the whitelist accounts for #line directives and such. If you
|
||||
// remove SkScalar from the whitelist, please change the filename here instead
|
||||
// of adding expected diagnostics.
|
||||
inline int headerSays(double x) {
|
||||
return x != x;
|
||||
}
|
||||
#line 9 "TestNANTestingExpr.cpp"
|
||||
void test(bool x);
|
||||
void foo() {
|
||||
float f, f2;
|
||||
|
|
Загрузка…
Ссылка в новой задаче