Skip to content

Commit

Permalink
SWDEV-179954 - OpenCL/LC - Merge branch amd-master into amd-common
Browse files Browse the repository at this point in the history
Change-Id: I184f1d6cf8ed5d0e52031a2916610c0486d44bd4
  • Loading branch information
Jenkins committed May 20, 2019
2 parents 5e309c4 + faf541e commit c8fbfa8
Show file tree
Hide file tree
Showing 63 changed files with 3,252 additions and 815 deletions.
36 changes: 26 additions & 10 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ class ClangTidyContext::CachedGlobList {

bool contains(StringRef S) {
switch (auto &Result = Cache[S]) {
case Yes: return true;
case No: return false;
case None:
Result = Globs.contains(S) ? Yes : No;
return Result == Yes;
case Yes:
return true;
case No:
return false;
case None:
Result = Globs.contains(S) ? Yes : No;
return Result == Yes;
}
llvm_unreachable("invalid enum");
}
Expand Down Expand Up @@ -387,16 +389,30 @@ static bool LineIsMarkedWithNOLINTinMacro(const SourceManager &SM,
return false;
}

namespace clang {
namespace tidy {

bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info, ClangTidyContext &Context,
bool CheckMacroExpansion) {
return Info.getLocation().isValid() &&
DiagLevel != DiagnosticsEngine::Error &&
DiagLevel != DiagnosticsEngine::Fatal &&
(CheckMacroExpansion ? LineIsMarkedWithNOLINTinMacro
: LineIsMarkedWithNOLINT)(Info.getSourceManager(),
Info.getLocation(),
Info.getID(), Context);
}

} // namespace tidy
} // namespace clang

void ClangTidyDiagnosticConsumer::HandleDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
return;

if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error &&
DiagLevel != DiagnosticsEngine::Fatal &&
LineIsMarkedWithNOLINTinMacro(Info.getSourceManager(),
Info.getLocation(), Info.getID(),
Context)) {
if (ShouldSuppressDiagnostic(DiagLevel, Info, Context)) {
++Context.Stats.ErrorsIgnoredNOLINT;
// Ignored a warning, should ignore related notes as well
LastErrorWasIgnored = true;
Expand Down
19 changes: 18 additions & 1 deletion clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ class ClangTidyContext {
bool AllowEnablingAnalyzerAlphaCheckers;
};

/// Check whether a given diagnostic should be suppressed due to the presence
/// of a "NOLINT" suppression comment.
/// This is exposed so that other tools that present clang-tidy diagnostics
/// (such as clangd) can respect the same suppression rules as clang-tidy.
/// This does not handle suppression of notes following a suppressed diagnostic;
/// that is left to the caller is it requires maintaining state in between calls
/// to this function.
/// The `CheckMacroExpansion` parameter determines whether the function should
/// handle the case where the diagnostic is inside a macro expansion. A degree
/// of control over this is needed because handling this case can require
/// examining source files other than the one in which the diagnostic is
/// located, and in some use cases we cannot rely on such other files being
/// mapped in the SourceMapper.
bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info, ClangTidyContext &Context,
bool CheckMacroExpansion = true);

/// \brief A diagnostic consumer that turns each \c Diagnostic into a
/// \c SourceManager-independent \c ClangTidyError.
//
Expand Down Expand Up @@ -246,7 +263,7 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {

/// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
/// according to the diagnostic \p Location.
void checkFilters(SourceLocation Location, const SourceManager& Sources);
void checkFilters(SourceLocation Location, const SourceManager &Sources);
bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;

ClangTidyContext &Context;
Expand Down
36 changes: 34 additions & 2 deletions clang-tools-extra/clangd/ClangdUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class CollectMainFileMacros : public PPCallbacks {
}

void EndOfMainFile() {
for (const auto& Entry : MainFileMacros)
for (const auto &Entry : MainFileMacros)
Out->push_back(Entry.getKey());
llvm::sort(*Out);
}

private:
private:
const SourceManager &SM;
bool InMainFile = true;
llvm::StringSet<> MainFileMacros;
Expand Down Expand Up @@ -332,6 +332,38 @@ ParsedAST::build(std::unique_ptr<CompilerInvocation> CI,
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(MainInput.getFile());
CTFactories.createChecks(CTContext.getPointer(), CTChecks);
ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) {
if (CTContext) {
std::string CheckName = CTContext->getCheckName(Info.getID());
bool IsClangTidyDiag = !CheckName.empty();
if (IsClangTidyDiag) {
// Check for warning-as-error.
// We deliberately let this take precedence over suppression comments
// to match clang-tidy's behaviour.
if (DiagLevel == DiagnosticsEngine::Warning &&
CTContext->treatAsError(CheckName)) {
return DiagnosticsEngine::Error;
}

// Check for suppression comment. Skip the check for diagnostics not
// in the main file, because we don't want that function to query the
// source buffer for preamble files. For the same reason, we ask
// ShouldSuppressDiagnostic not to follow macro expansions, since
// those might take us into a preamble file as well.
bool IsInsideMainFile =
Info.hasSourceManager() &&
Info.getSourceManager().isWrittenInMainFile(
Info.getSourceManager().getFileLoc(Info.getLocation()));
if (IsInsideMainFile && tidy::ShouldSuppressDiagnostic(
DiagLevel, Info, *CTContext,
/* CheckMacroExpansion = */ false)) {
return DiagnosticsEngine::Ignored;
}
}
}
return DiagLevel;
});
Preprocessor *PP = &Clang->getPreprocessor();
for (const auto &Check : CTChecks) {
// FIXME: the PP callbacks skip the entire preamble.
Expand Down
16 changes: 16 additions & 0 deletions clang-tools-extra/clangd/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
// Handle the new main diagnostic.
flushLastDiag();

if (Adjuster) {
DiagLevel = Adjuster(DiagLevel, Info);
if (DiagLevel == DiagnosticsEngine::Ignored) {
LastPrimaryDiagnosticWasSuppressed = true;
return;
}
}
LastPrimaryDiagnosticWasSuppressed = false;

LastDiag = Diag();
LastDiag->ID = Info.getID();
FillDiagBase(*LastDiag);
Expand All @@ -528,6 +537,13 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
}
} else {
// Handle a note to an existing diagnostic.

// If a diagnostic was suppressed due to the suppression filter,
// also suppress notes associated with it.
if (LastPrimaryDiagnosticWasSuppressed) {
return;
}

if (!LastDiag) {
assert(false && "Adding a note without main diagnostic");
IgnoreDiagnostics::log(DiagLevel, Info);
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/clangd/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,25 @@ class StoreDiags : public DiagnosticConsumer {

using DiagFixer = std::function<std::vector<Fix>(DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
using LevelAdjuster = std::function<DiagnosticsEngine::Level(
DiagnosticsEngine::Level, const clang::Diagnostic &)>;
/// If set, possibly adds fixes for diagnostics using \p Fixer.
void contributeFixes(DiagFixer Fixer) { this->Fixer = Fixer; }
/// If set, this allows the client of this class to adjust the level of
/// diagnostics, such as promoting warnings to errors, or ignoring
/// diagnostics.
void setLevelAdjuster(LevelAdjuster Adjuster) { this->Adjuster = Adjuster; }

private:
void flushLastDiag();

DiagFixer Fixer = nullptr;
LevelAdjuster Adjuster = nullptr;
std::vector<Diag> Output;
llvm::Optional<LangOptions> LangOpts;
llvm::Optional<Diag> LastDiag;
llvm::DenseSet<int> IncludeLinesWithErrors;
bool LastPrimaryDiagnosticWasSuppressed = false;
};

} // namespace clangd
Expand Down
60 changes: 60 additions & 0 deletions clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ MATCHER_P(EqualToLSPDiag, LSPDiag,

MATCHER_P(DiagSource, S, "") { return arg.Source == S; }
MATCHER_P(DiagName, N, "") { return arg.Name == N; }
MATCHER_P(DiagSeverity, S, "") { return arg.Severity == S; }

MATCHER_P(EqualToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
if (arg.Message != Fix.Message)
Expand Down Expand Up @@ -207,6 +208,64 @@ TEST(DiagnosticsTest, ClangTidy) {
"multiple unsequenced modifications to 'y'")));
}

TEST(DiagnosticTest, ClangTidySuppressionComment) {
Annotations Main(R"cpp(
int main() {
int i = 3;
double d = 8 / i; // NOLINT
// NOLINTNEXTLINE
double e = 8 / i;
double f = [[8]] / i;
}
)cpp");
TestTU TU = TestTU::withCode(Main.code());
TU.ClangTidyChecks = "bugprone-integer-division";
EXPECT_THAT(
TU.build().getDiagnostics(),
UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "result of integer division used in a floating "
"point context; possible loss of precision"),
DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"))));
}

TEST(DiagnosticTest, ClangTidyWarningAsError) {
Annotations Main(R"cpp(
int main() {
int i = 3;
double f = [[8]] / i;
}
)cpp");
TestTU TU = TestTU::withCode(Main.code());
TU.ClangTidyChecks = "bugprone-integer-division";
TU.ClangTidyWarningsAsErrors = "bugprone-integer-division";
EXPECT_THAT(
TU.build().getDiagnostics(),
UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "result of integer division used in a floating "
"point context; possible loss of precision"),
DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"),
DiagSeverity(DiagnosticsEngine::Error))));
}

TEST(DiagnosticTest, ClangTidyWarningAsErrorTrumpsSuppressionComment) {
Annotations Main(R"cpp(
int main() {
int i = 3;
double f = [[8]] / i; // NOLINT
}
)cpp");
TestTU TU = TestTU::withCode(Main.code());
TU.ClangTidyChecks = "bugprone-integer-division";
TU.ClangTidyWarningsAsErrors = "bugprone-integer-division";
EXPECT_THAT(
TU.build().getDiagnostics(),
UnorderedElementsAre(::testing::AllOf(
Diag(Main.range(), "result of integer division used in a floating "
"point context; possible loss of precision"),
DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"),
DiagSeverity(DiagnosticsEngine::Error))));
}

TEST(DiagnosticsTest, Preprocessor) {
// This looks like a preamble, but there's an #else in the middle!
// Check that:
Expand Down Expand Up @@ -767,6 +826,7 @@ TEST(DiagsInHeaders, OnlyErrorOrFatal) {
"a type specifier for all declarations"),
WithNote(Diag(Header.range(), "error occurred here")))));
}

} // namespace

} // namespace clangd
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/unittests/TestTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ParsedAST TestTU::build() const {
Inputs.FS = buildTestFS(Files);
Inputs.Opts = ParseOptions();
Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
Inputs.Index = ExternalIndex;
if (Inputs.Index)
Inputs.Opts.SuggestMissingIncludes = true;
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/unittests/TestTU.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct TestTU {
std::vector<const char *> ExtraArgs;

llvm::Optional<std::string> ClangTidyChecks;
llvm::Optional<std::string> ClangTidyWarningsAsErrors;
// Index to use when building AST.
const SymbolIndex *ExternalIndex = nullptr;

Expand Down
18 changes: 18 additions & 0 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ class ASTNodeTraverser
});
}

void Visit(const ast_type_traits::DynTypedNode &N) {
// FIXME: Improve this with a switch or a visitor pattern.
if (const auto *D = N.get<Decl>())
Visit(D);
else if (const auto *S = N.get<Stmt>())
Visit(S);
else if (const auto *QT = N.get<QualType>())
Visit(*QT);
else if (const auto *T = N.get<Type>())
Visit(T);
else if (const auto *C = N.get<CXXCtorInitializer>())
Visit(C);
else if (const auto *C = N.get<OMPClause>())
Visit(C);
else if (const auto *T = N.get<TemplateArgument>())
Visit(*T);
}

void dumpDeclContext(const DeclContext *DC) {
if (!DC)
return;
Expand Down
19 changes: 19 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ def err_drv_invalid_riscv_arch_name : Error<
"invalid arch name '%0', %1">;
def err_drv_invalid_riscv_ext_arch_name : Error<
"invalid arch name '%0', %1 '%2'">;
def warn_drv_avr_mcu_not_specified : Warning<
"no target microcontroller specified on command line, cannot "
"link standard libraries, please pass -mmcu=<mcu name>">,
InGroup<AVRRtlibLinkingQuirks>;
def warn_drv_avr_gcc_not_found: Warning<
"no avr-gcc installation can be found on the system, "
"cannot link standard libraries">,
InGroup<AVRRtlibLinkingQuirks>;
def warn_drv_avr_libc_not_found: Warning<
"no avr-libc installation can be found on the system, "
"cannot link standard libraries">,
InGroup<AVRRtlibLinkingQuirks>;
def warn_drv_avr_family_linking_stdlibs_not_implemented: Warning<
"support for linking stdlibs for microcontroller '%0' is not implemented">,
InGroup<AVRRtlibLinkingQuirks>;
def warn_drv_avr_stdlib_not_linked: Warning<
"standard library not linked and so no interrupt vector table or "
"compiler runtime routines will be linked">,
InGroup<AVRRtlibLinkingQuirks>;
def err_drv_cuda_bad_gpu_arch : Error<"Unsupported CUDA gpu architecture: %0">;
def err_drv_no_cuda_installation : Error<
"cannot find CUDA installation. Provide its path via --cuda-path, or pass "
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@ def SerializedDiagnostics : DiagGroup<"serialized-diagnostics">;
// compiling CUDA C/C++ but which is not compatible with the CUDA spec.
def CudaCompat : DiagGroup<"cuda-compat">;

// Warnings which cause linking of the runtime libraries like
// libc and the CRT to be skipped.
def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;

// A warning group for things that will change semantics in the future.
def FutureCompat : DiagGroup<"future-compat">;

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def warn_cxx98_compat_alignof : Warning<
InGroup<CXX98Compat>, DefaultIgnore;
def ext_alignof_expr : ExtWarn<
"%0 applied to an expression is a GNU extension">, InGroup<GNUAlignofExpression>;
def err_lambda_after_delete : Error<
"'[]' after delete interpreted as 'delete[]'; add parentheses to treat this as a lambda-expression">;

def warn_microsoft_dependent_exists : Warning<
"dependent %select{__if_not_exists|__if_exists}0 declarations are ignored">,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class NonLoc : public DefinedSVal {

static bool isCompoundType(QualType T) {
return T->isArrayType() || T->isRecordType() ||
T->isComplexType() || T->isVectorType();
T->isAnyComplexType() || T->isVectorType();
}

private:
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5325,7 +5325,7 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
return ImportedDefOrErr.takeError();
}

VarTemplateDecl *VarTemplate;
VarTemplateDecl *VarTemplate = nullptr;
if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
return std::move(Err);

Expand Down Expand Up @@ -8010,7 +8010,7 @@ ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {

while (!NestedNames.empty()) {
NNS = NestedNames.pop_back_val();
NestedNameSpecifier *Spec;
NestedNameSpecifier *Spec = nullptr;
if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
return std::move(Err);

Expand Down
Loading

0 comments on commit c8fbfa8

Please sign in to comment.