This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add check name to YAML export
ClosedPublic

Authored by Alpha on Oct 31 2016, 3:15 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

Alpha updated this revision to Diff 76369.Oct 31 2016, 3:15 AM
Alpha retitled this revision from to [clang-tidy] Add check name to YAML export.
Alpha updated this object.
Alpha added reviewers: alexfh, klimek, djasper.
Alpha added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.
Eugene.Zelenko added a subscriber: Prazek.
Alpha updated this revision to Diff 76849.EditedNov 3 2016, 5:52 AM
Alpha removed rL LLVM as the repository for this revision.

Fix diagnostic deserialization bug for clang-apply-replacements.

Alpha set the repository for this revision to rL LLVM.Nov 3 2016, 5:54 AM
Alpha updated this revision to Diff 76850.Nov 3 2016, 6:03 AM

Remove debug symbols.

Alpha updated this revision to Diff 77029.Nov 7 2016, 6:30 AM

Ignore export of empty fixes.

alexfh requested changes to this revision.Nov 7 2016, 11:52 AM
alexfh edited edge metadata.

Thank you for resurrecting this patch! A few comments inline.

include/clang/Tooling/Core/Diagnostic.h
35 ↗(On Diff #77029)

What are the constraints on the location? Should it be a file location or macro locations are fine too? Please add a (doxygen-style) comment.

57 ↗(On Diff #77029)

CheckName is somewhat clang-tidy specific. We need something more generic here, e.g. DiagnosticName, Category or somesuch.

Please add a (doxygen-style) comment to this and other fields here.

68–71 ↗(On Diff #77029)

That's too vague. Are you intending to use it only for reporting problems with replacement deduplication? Should it be in this structure at all?

include/clang/Tooling/DiagnosticsYaml.h
82 ↗(On Diff #77029)

nit: Formatting is off.

tools/extra/clang-tidy/ClangTidy.cpp
578 ↗(On Diff #77029)

This function neither fills TUD.MainSourceFile nor TUD.Context (which I'm not sure even belongs to this structure).

579 ↗(On Diff #77029)

I somewhat dislike the implicit object slicing that happens here. I'd prefer to make this a loop with explicit conversion.

tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
116 ↗(On Diff #77029)

No need for clang:: here.

This revision now requires changes to proceed.Nov 7 2016, 11:52 AM
Alpha added inline comments.Nov 8 2016, 8:07 AM
include/clang/Tooling/Core/Diagnostic.h
35 ↗(On Diff #77029)

Indeed, this should be a file location.

68–71 ↗(On Diff #77029)

This was actually left to keep compatibility with TranslationUnitReplacements which was used for the export.
But it seems that even for that structure, there is in all likelihood no reference to any use of the Context field, except in test cases and in the Yaml IO mapping, where it is marked as an optional entry.
Should it be discarded instead (here, and thus also in TranslationUnitReplacements)?

tools/extra/clang-tidy/ClangTidy.cpp
578 ↗(On Diff #77029)

Done for MainSourceFile which was surprisingly never exported with the fixes.
For Context, see above comment about the 'TranslationUnitDiagnostics' structure.

Alpha updated this revision to Diff 77196.Nov 8 2016, 8:13 AM
Alpha edited edge metadata.

Export effectively MainSourceFile.
Change CheckName field.
Add doxygen-style comments.

Alpha marked 6 inline comments as done.Nov 8 2016, 8:15 AM

What happens to diagnostics without fixes? e.g. from the readability-function-size check.

Alpha added a comment.Nov 22 2016, 7:05 AM

This shouldn't affect diagnostics without fixes. If there is no fix, there won't be anything to export, and the diagnostic just behaves normally.

This shouldn't affect diagnostics without fixes. If there is no fix, there won't be anything to export, and the diagnostic just behaves normally.

That's a shame; I need a machine readable report of all diagnostics.

Alpha added a comment.Nov 22 2016, 8:04 AM

This shouldn't affect diagnostics without fixes. If there is no fix, there won't be anything to export, and the diagnostic just behaves normally.

That's a shame; I need a machine readable report of all diagnostics.

This is not the aim of this change-set. The objective here is only to associate a replacement to the diagnostic from which it was emitted. But having a parse-able output for all clang-tidy's diagnostics can indeed be a nice feature to add in a different patch.

I'll try to get back to this code review soon. Sorry for the delay.

alexfh requested changes to this revision.Nov 30 2016, 8:34 AM
alexfh edited edge metadata.

Looks mostly good. A few more nits.

include/clang/Tooling/Core/Diagnostic.h
36 ↗(On Diff #77196)

nit: Add a trailing period.

68–71 ↗(On Diff #77029)

Yes, it seems we can just remove the Context field.

include/clang/Tooling/DiagnosticsYaml.h
35 ↗(On Diff #77196)

Initializers for non-trivial members are superfluous. Looks like only DiagLevel initializer makes sense, but I'd use an explicit value for it.

58 ↗(On Diff #77196)

clang-format, please

79 ↗(On Diff #77196)

Should we copy all diagnostics instead?

tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
42 ↗(On Diff #77196)

clang-format, please

tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
56 ↗(On Diff #77196)

It might make sense to move BuildDirectory to clang::Tooling::Diagnostic as well.

This revision now requires changes to proceed.Nov 30 2016, 8:34 AM
Alpha marked 10 inline comments as done.Dec 1 2016, 5:39 AM
Alpha added inline comments.
include/clang/Tooling/DiagnosticsYaml.h
79 ↗(On Diff #77196)

I am not sure about that. Copying all diagnostics will mean having empty entries in the replacement files with just a check name. This might seem useless, the problem being that at the moment, the only useful exported information in diagnostics are the replacements. I think that if all diagnostics are copied, it must be done in a different patch, with a proper export of all the meaningful information about the diagnostics.
Then, the exported info in clang-tidy will not solely be fixes, but every diagnostic info (which could mean changing the name and meaning of output file and option). What is your feeling about this?

Alpha updated this revision to Diff 79899.Dec 1 2016, 5:40 AM
Alpha edited edge metadata.
alexfh accepted this revision.Dec 1 2016, 5:53 AM
alexfh edited edge metadata.

LG with a comment.

include/clang/Tooling/DiagnosticsYaml.h
79 ↗(On Diff #77196)

Please add a FIXME to MappingTraits<clang::tooling::Diagnostic>::mapping to properly export locations, messages, notes, diagnostic levels and all other fields. And a FIXME here to export all diagnostics, not just the ones with fixes.

This revision is now accepted and ready to land.Dec 1 2016, 5:53 AM
Alpha updated this revision to Diff 79904.Dec 1 2016, 6:21 AM
Alpha edited edge metadata.
Alpha marked 3 inline comments as done.
alexfh added a comment.Dec 1 2016, 6:55 AM

Do you have commit access? If you need me to commit the patch for you, please rebase it on top of HEAD.

Alpha updated this revision to Diff 79917.Dec 1 2016, 8:30 AM

Rebase on top of HEAD.

Alpha added a comment.Dec 1 2016, 8:32 AM

I don't have commit access.

Thank you for the review @alexfh

Alpha updated this revision to Diff 80732.Dec 8 2016, 2:10 AM

Rebase on top of HEAD.
Ping.

alexfh added a comment.Dec 8 2016, 7:12 AM

The patch spans two repos, so I couldn't apply it using arcanist. Just made it "manually" (patch -p0 -i ...); now running tests...

alexfh requested changes to this revision.Dec 8 2016, 8:20 AM
alexfh edited edge metadata.

Looks like compiler has found a couple of bugs:

In file included from llvm.git/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp:38:
llvm.git/tools/clang/include/clang/Tooling/DiagnosticsYaml.h:38:53: error: field 'Message' is uninitialized when used here [-Werror,-Wuninitialized]
        : DiagnosticName(D.DiagnosticName), Message(Message), Fix(D.Fix),
                                                    ^
llvm.git/tools/clang/include/clang/Tooling/DiagnosticsYaml.h:70:7: error: ignoring return value of function declared with warn_unused_result attribute [-Werror,-Wunused-result]
      Keys->Fix[Fix.getFilePath()].add(Fix);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
2 errors generated.

Please fix.

This revision now requires changes to proceed.Dec 8 2016, 8:20 AM
Alpha updated this revision to Diff 80874.Dec 9 2016, 2:45 AM
Alpha edited edge metadata.

Fix clang compilation warnings. These didn't appear when compiled on Windows.
Tested on a Linux distribution, should be fixed.

alexfh added a comment.Dec 9 2016, 5:35 AM

Have you run the tests? I see a number of failures:

$ ninja check-clang-tools
...
Failing Tests (6):
    Clang Tools :: clang-apply-replacements/basic.cpp
    Clang Tools :: clang-apply-replacements/conflict.cpp
    Clang Tools :: clang-apply-replacements/crlf.cpp
    Clang Tools :: clang-apply-replacements/format.cpp
    Clang Tools :: clang-rename/ClassReplacements.cpp
    Clang Tools :: clang-tidy/clang-tidy-run-with-database.cpp

  Expected Passes    : 488
  Expected Failures  : 1
  Unexpected Failures: 6
alexfh requested changes to this revision.Dec 13 2016, 6:54 AM
alexfh edited edge metadata.
This revision now requires changes to proceed.Dec 13 2016, 6:54 AM
Alpha updated this revision to Diff 81779.Dec 16 2016, 11:27 AM
Alpha edited edge metadata.

It was tested against the clang extra unit tests, but not tests run with check-clang-tools.
Updated Yaml test files to match the new format, this might need further review.

Alpha updated this revision to Diff 82860.Jan 3 2017, 3:39 AM
Alpha edited edge metadata.

Rebase on top of HEAD.
Ping.

alexfh added a comment.Jan 3 2017, 5:48 AM

Err, looks like I forgot to post comments I entered a few days ago.

Just a few nits.

include/clang/Tooling/Core/Diagnostic.h
62 ↗(On Diff #82860)

nit: No need for tooling::.

lib/Tooling/Core/Diagnostic.cpp
39 ↗(On Diff #82860)

nit: No need for tooling::.

tools/extra/clang-tidy/ClangTidy.cpp
106 ↗(On Diff #81779)

Why this change?

tools/extra/clang-tidy/ClangTidy.h
245 ↗(On Diff #81779)

Top-level const on function parameters in function declarations is useless (it's not a part of the function prototype and it tells nothing to the function users). It might make sense on a function definition, if used consistently (same way as on local variables). However, is not very common in LLVM/Clang.

tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
45 ↗(On Diff #82860)

nit: No need for clang::.

36 ↗(On Diff #81779)

Do we actually need this typedef? How much is the old type name used?

alexfh accepted this revision.Jan 3 2017, 6:42 AM
alexfh edited edge metadata.

Looks good.

Fixed the issues myself and running tests before committing this.

Thank you for working on this!

tools/extra/clang-tidy/ClangTidy.cpp
106 ↗(On Diff #81779)

Assuming, it was unintentional, changing back to reference.

tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
36 ↗(On Diff #81779)

Removed.

This revision is now accepted and ready to land.Jan 3 2017, 6:42 AM
This revision was automatically updated to reflect the committed changes.
Alpha added a comment.Jan 3 2017, 8:38 AM

Thanks for the review!

tools/extra/clang-tidy/ClangTidy.cpp
106 ↗(On Diff #81779)

It is indeed unintentional.

tools/extra/clang-tidy/ClangTidy.h
245 ↗(On Diff #81779)

Ok, this is good to know.

tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
36 ↗(On Diff #81779)

I was quite hesitant with this one, wondering if it would be better to keep clang-tidy specific naming in that case.