Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW46-47)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Nov 24, 2021
2 parents 2869ca7 + 3c3ca19 commit 185983b
Show file tree
Hide file tree
Showing 5,688 changed files with 226,266 additions and 93,865 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "clang/Tooling/DiagnosticsYaml.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -152,9 +153,13 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
DiagReplacements;

auto AddToGroup = [&](const tooling::Replacement &R,
const tooling::TranslationUnitDiagnostics *SourceTU) {
const tooling::TranslationUnitDiagnostics *SourceTU,
const llvm::Optional<std::string> BuildDir) {
// Use the file manager to deduplicate paths. FileEntries are
// automatically canonicalized.
auto PrevWorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
if (BuildDir)
SM.getFileManager().getFileSystemOpts().WorkingDir = std::move(*BuildDir);
if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) {
if (SourceTU) {
auto &Replaces = DiagReplacements[*Entry];
Expand All @@ -170,18 +175,19 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
errs() << "Described file '" << R.getFilePath()
<< "' doesn't exist. Ignoring...\n";
}
SM.getFileManager().getFileSystemOpts().WorkingDir = PrevWorkingDir;
};

for (const auto &TU : TUs)
for (const tooling::Replacement &R : TU.Replacements)
AddToGroup(R, nullptr);
AddToGroup(R, nullptr, {});

for (const auto &TU : TUDs)
for (const auto &D : TU.Diagnostics)
if (const auto *ChoosenFix = tooling::selectFirstFix(D)) {
for (const auto &Fix : *ChoosenFix)
for (const tooling::Replacement &R : Fix.second)
AddToGroup(R, &TU);
AddToGroup(R, &TU, D.BuildDirectory);
}

// Sort replacements per file to keep consistent behavior when
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context,
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER

std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
ClangTidyASTConsumerFactory::createASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
// FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
// modify Compiler.
Expand Down Expand Up @@ -573,7 +573,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
Action(ClangTidyASTConsumerFactory *Factory) : Factory(Factory) {}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
StringRef File) override {
return Factory->CreateASTConsumer(Compiler, File);
return Factory->createASTConsumer(Compiler, File);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/ClangTidy.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ClangTidyASTConsumerFactory {

/// Returns an ASTConsumer that runs the specified clang-tidy checks.
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
createASTConsumer(clang::CompilerInstance &Compiler, StringRef File);

/// Get the list of enabled checks.
std::vector<std::string> getCheckNames();
Expand Down
20 changes: 5 additions & 15 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
? tooling::DiagnosticMessage(Message, Loc.getManager(), Loc)
: tooling::DiagnosticMessage(Message);

// Make sure that if a TokenRange is receieved from the check it is unfurled
// Make sure that if a TokenRange is received from the check it is unfurled
// into a real CharRange for the diagnostic printer later.
// Whatever we store here gets decoupled from the current SourceManager, so
// we **have to** know the exact position and length of the highlight.
Expand Down Expand Up @@ -376,10 +376,10 @@ static ClangTidyError createNolintError(const ClangTidyContext &Context,
Context.getCurrentBuildDirectory(), false);
StringRef Message =
IsNolintBegin
? "unmatched 'NOLINTBEGIN' comment without a subsequent 'NOLINTEND' "
"comment"
: "unmatched 'NOLINTEND' comment without a previous 'NOLINTBEGIN' "
"comment";
? ("unmatched 'NOLINTBEGIN' comment without a subsequent 'NOLINT"
"END' comment")
: ("unmatched 'NOLINTEND' comment without a previous 'NOLINT"
"BEGIN' comment");
Error.Message = tooling::DiagnosticMessage(Message, SM, Loc);
return Error;
}
Expand Down Expand Up @@ -517,16 +517,6 @@ static bool lineIsMarkedWithNOLINTinMacro(
namespace clang {
namespace tidy {

bool shouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info, ClangTidyContext &Context,
bool AllowIO) {
SmallVector<ClangTidyError, 1> Unused;
bool ShouldSuppress =
shouldSuppressDiagnostic(DiagLevel, Info, Context, Unused, AllowIO);
assert(Unused.empty());
return ShouldSuppress;
}

bool shouldSuppressDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
ClangTidyContext &Context,
Expand Down
25 changes: 8 additions & 17 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class CompilerInstance;
class SourceManager;
namespace ast_matchers {
class MatchFinder;
}
} // namespace ast_matchers
namespace tooling {
class CompilationDatabase;
}
} // namespace tooling

namespace tidy {

Expand All @@ -45,18 +45,13 @@ struct ClangTidyError : tooling::Diagnostic {
std::vector<std::string> EnabledDiagnosticAliases;
};

/// Contains displayed and ignored diagnostic counters for a ClangTidy
/// run.
/// Contains displayed and ignored diagnostic counters for a ClangTidy run.
struct ClangTidyStats {
ClangTidyStats()
: ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), ErrorsIgnoredNOLINT(0),
ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}

unsigned ErrorsDisplayed;
unsigned ErrorsIgnoredCheckFilter;
unsigned ErrorsIgnoredNOLINT;
unsigned ErrorsIgnoredNonUserCode;
unsigned ErrorsIgnoredLineFilter;
unsigned ErrorsDisplayed = 0;
unsigned ErrorsIgnoredCheckFilter = 0;
unsigned ErrorsIgnoredNOLINT = 0;
unsigned ErrorsIgnoredNonUserCode = 0;
unsigned ErrorsIgnoredLineFilter = 0;

unsigned errorsIgnored() const {
return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +
Expand Down Expand Up @@ -228,10 +223,6 @@ class ClangTidyContext {
/// for example, the use of a "NOLINTBEGIN" comment that is not followed by a
/// "NOLINTEND" comment - a diagnostic regarding the improper use is returned
/// via the output argument `SuppressionErrors`.
bool shouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info, ClangTidyContext &Context,
bool AllowIO = true);

bool shouldSuppressDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
ClangTidyContext &Context,
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/ClangTidyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct ClangTidyOptions {

std::string Value;
/// Priority stores relative precedence of the value loaded from config
/// files to disambigute local vs global value from different levels.
/// files to disambiguate local vs global value from different levels.
unsigned Priority;
};
typedef std::pair<std::string, std::string> StringPair;
Expand All @@ -129,8 +129,8 @@ struct ClangTidyOptions {
/// and using a FileOptionsProvider, it will take a configuration file in the
/// parent directory (if any exists) and apply this config file on top of the
/// parent one. IF true and using a ConfigOptionsProvider, it will apply this
/// config on top of any configuation file it finds in the directory using the
/// same logic as FileOptionsProvider. If false or missing, only this
/// config on top of any configuration file it finds in the directory using
/// the same logic as FileOptionsProvider. If false or missing, only this
/// configuration file will be used.
llvm::Optional<bool> InheritParentConfig;

Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "CleanupCtadCheck.h"
#include "DurationAdditionCheck.h"
#include "DurationComparisonCheck.h"
#include "DurationConversionCastCheck.h"
Expand All @@ -35,6 +36,7 @@ namespace abseil {
class AbseilModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<CleanupCtadCheck>("abseil-cleanup-ctad");
CheckFactories.registerCheck<DurationAdditionCheck>(
"abseil-duration-addition");
CheckFactories.registerCheck<DurationComparisonCheck>(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS

add_clang_library(clangTidyAbseilModule
AbseilTidyModule.cpp
CleanupCtadCheck.cpp
DurationAdditionCheck.cpp
DurationComparisonCheck.cpp
DurationConversionCastCheck.cpp
Expand Down
49 changes: 49 additions & 0 deletions clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===--- CleanupCtadCheck.cpp - clang-tidy --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "CleanupCtadCheck.h"
#include "../utils/TransformerClangTidyCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Transformer/RangeSelector.h"
#include "clang/Tooling/Transformer/RewriteRule.h"
#include "clang/Tooling/Transformer/Stencil.h"
#include "llvm/ADT/StringRef.h"

using namespace ::clang::ast_matchers;
using namespace ::clang::transformer;

namespace clang {
namespace tidy {
namespace abseil {

RewriteRule CleanupCtadCheckImpl() {
auto warning_message = cat("prefer absl::Cleanup's class template argument "
"deduction pattern in C++17 and higher");

return makeRule(
declStmt(has(varDecl(
hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
hasInitializer(traverse(
clang::TK_IgnoreUnlessSpelledInSource,
callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
argumentCountIs(1),
hasArgument(0, expr().bind("make_cleanup_argument")))
.bind("make_cleanup_call")))))),
{changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
changeTo(node("make_cleanup_call"), cat(node("make_cleanup_argument")))},
warning_message);
}

CleanupCtadCheck::CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
: utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}

} // namespace abseil
} // namespace tidy
} // namespace clang
37 changes: 37 additions & 0 deletions clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===--- CleanupCtadCheck.h - clang-tidy ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_CLEANUPCTADCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_CLEANUPCTADCHECK_H

#include "../utils/TransformerClangTidyCheck.h"

namespace clang {
namespace tidy {
namespace abseil {

/// Suggests switching the initialization pattern of `absl::Cleanup`
/// instances from the factory function to class template argument
/// deduction (CTAD), in C++17 and higher.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/abseil-cleanup-ctad.html
class CleanupCtadCheck : public utils::TransformerClangTidyCheck {
public:
CleanupCtadCheck(StringRef Name, ClangTidyContext *Context);

bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus17;
}
};

} // namespace abseil
} // namespace tidy
} // namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_CLEANUPCTADCHECK_H
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class DurationDivisionCheck : public ClangTidyCheck {
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &result) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

} // namespace abseil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
return;

// We first handle the cases of literal zero (both float and integer).
if (IsLiteralZero(Result, *Arg)) {
if (isLiteralZero(Result, *Arg)) {
diag(Call->getBeginLoc(),
"use ZeroDuration() for zero-length time intervals")
<< FixItHint::CreateReplacement(Call->getSourceRange(),
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ llvm::StringRef getTimeInverseForScale(DurationScale Scale) {
}

/// Returns `true` if `Node` is a value which evaluates to a literal `0`.
bool IsLiteralZero(const MatchFinder::MatchResult &Result, const Expr &Node) {
bool isLiteralZero(const MatchFinder::MatchResult &Result, const Expr &Node) {
auto ZeroMatcher =
anyOf(integerLiteral(equals(0)), floatLiteral(equals(0.0)));

Expand Down Expand Up @@ -276,7 +276,7 @@ std::string rewriteExprFromNumberToDuration(
rewriteInverseDurationCall(Result, Scale, RootNode))
return *MaybeRewrite;

if (IsLiteralZero(Result, RootNode))
if (isLiteralZero(Result, RootNode))
return std::string("absl::ZeroDuration()");

return (llvm::Twine(getDurationFactoryForScale(Scale)) + "(" +
Expand All @@ -294,7 +294,7 @@ std::string rewriteExprFromNumberToTime(
rewriteInverseTimeCall(Result, Scale, RootNode))
return *MaybeRewrite;

if (IsLiteralZero(Result, RootNode))
if (isLiteralZero(Result, RootNode))
return std::string("absl::UnixEpoch()");

return (llvm::Twine(getTimeFactoryForScale(Scale)) + "(" +
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ llvm::StringRef getDurationFactoryForScale(DurationScale Scale);

/// Given a 'Scale', return the appropriate factory function call for
/// constructing a `Time` for that scale.
llvm::StringRef getTimeFactoryForScale(DurationScale scale);
llvm::StringRef getTimeFactoryForScale(DurationScale Scale);

// Determine if `Node` represents a literal floating point or integral zero.
bool IsLiteralZero(const ast_matchers::MatchFinder::MatchResult &Result,
bool isLiteralZero(const ast_matchers::MatchFinder::MatchResult &Result,
const Expr &Node);

/// Possibly strip a floating point cast expression.
Expand Down Expand Up @@ -77,7 +77,7 @@ const std::pair<llvm::StringRef, llvm::StringRef> &
getDurationInverseForScale(DurationScale Scale);

/// Returns the Time inverse function name for a given `Scale`.
llvm::StringRef getTimeInverseForScale(DurationScale scale);
llvm::StringRef getTimeInverseForScale(DurationScale Scale);

/// Assuming `Node` has type `double` or `int` representing a time interval of
/// `Scale`, return the expression to make it a suitable `Duration`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
", " + NeedleExprCode + ")")
.str());

// Create a preprocessor #include FixIt hint (CreateIncludeInsertion checks
// Create a preprocessor #include FixIt hint (createIncludeInsertion checks
// whether this already exists).
Diagnostic << IncludeInserter.createIncludeInsertion(
Source.getFileID(ComparisonExpr->getBeginLoc()),
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ bool UnrollLoopsCheck::extractValue(int &Value, const BinaryOperator *Op,
else if (RHS->isEvaluatable(*Context))
RHS->EvaluateAsRValue(Result, *Context);
else
return false; // Cannot evalue either side.
return false; // Cannot evaluate either side.
if (!Result.Val.isInt())
return false; // Cannot check number of iterations, return false to be
// safe.
Expand Down
Loading

0 comments on commit 185983b

Please sign in to comment.