This is an archive of the discontinued LLVM Phabricator instance.

[clangd] More precisely enable clang warnings through ClangTidy options
ClosedPublic

Authored by sammccall on Apr 29 2022, 8:48 AM.

Details

Summary

clang-tidy's behavior is to add the -W flags, and then map all clang diagnostics
to "clang-diagnostic-foo" pseudo-check-names, then use Checks to filter those.

Previous to this patch, we were handling -W flags but not filtering the
diagnostics, assuming both sets of information encoded the same thing.

However this intersection is nontrivial when diagnostic group hierarchy is
involved. e.g. -Wunused + clang-diagnostic-unused-function should not enable
unused label warnings.

This patch more closely emulates clang-tidy's behavior, while not going to
the extreme of generating tidy check names for all clang diagnostics and
filtering them with regexes.

Diff Detail

Event Timeline

sammccall created this revision.Apr 29 2022, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 8:48 AM
sammccall requested review of this revision.Apr 29 2022, 8:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 29 2022, 8:48 AM
kadircet accepted this revision.Apr 29 2022, 9:10 AM

thanks, lgtm!

clang-tools-extra/clangd/ParsedAST.cpp
240

s/clang-diagnostics-unused function/clang-diagnostics-unused-function/

254

static constexpr

This revision is now accepted and ready to land.Apr 29 2022, 9:10 AM
This revision was landed with ongoing or failed builds.Apr 29 2022, 1:30 PM
This revision was automatically updated to reflect the committed changes.
kstoimenov added inline comments.
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
558

This breaks sanitizer buildbot: https://lab.llvm.org/buildbot/#/builders/5/builds/22933.

Could you please fix or revert?

/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:558
Value of: *TU.build().getDiagnostics()
Expected: has 1 element that (Diag at 1:16-1:19 = [unused function 'foo']) and (diag name "-Wunused-function") and (diag source 1) and (diag severity 3)
  Actual: { [1:16-1:19] unused function 'foo', [1:16-1:19] declaration must be declared within the '__llvm_libc' namespace }, which has 2 elements
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:562
Value of: *TU.build().getDiagnostics()
Expected: is empty
  Actual: { [1:16-1:19] declaration must be declared within the '__llvm_libc' namespace }, whose size is 1

Thanks for revert, and apologies for missing the bots.

(I did of course run the tests locally, but in a weird config that didn't trigger the failure)