This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Merge 2 parseIWYUPragma impls in libToolingInclusions
ClosedPublic

Authored by sammccall on Nov 28 2022, 1:36 AM.

Details

Summary

Based on include-cleaner's version, but:

  • remove assert that can fail for input /\<newline>* */
  • assert was also checking the wrong condition: that the prefix *differed* from either // or from /*. Avoid use of strncmp where we can.
  • add a comment that the brittleness of the text matching is intentional

Diff Detail

Event Timeline

sammccall created this revision.Nov 28 2022, 1:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 1:36 AM
Herald added a subscriber: kadircet. · View Herald Transcript
sammccall requested review of this revision.Nov 28 2022, 1:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 1:36 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thanks! The change is LG, I think it would be great to have some tests.

clang-tools-extra/include-cleaner/lib/Record.cpp
143–144

I'd like to have some unittests for this function (the cases you mentioned are really good, I don't want to lose them), but this function is not exposed. Maybe expose it or even address the FIXME?

sammccall updated this revision to Diff 478162.Nov 28 2022, 2:16 AM
sammccall retitled this revision from [include-cleaner] Minor fixes to parseIWYUPragma: to [include-cleaner] Merge 2 parseIWYUPragma impls in libToolingInclusions.
sammccall edited the summary of this revision. (Show Details)

Move to libTooling, remove clangd impl, add tests

Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 2:16 AM
Herald added a subscriber: arphaman. · View Herald Transcript
sammccall updated this revision to Diff 478163.Nov 28 2022, 2:16 AM

clean dead tests

sammccall added inline comments.Nov 28 2022, 2:19 AM
clang-tools-extra/include-cleaner/lib/Record.cpp
143–144

Done.

This stings a little as I'd recently done this in 5d2d527c32, after which D136071 copied the impl without any tests and added new bugs.

sammccall updated this revision to Diff 478170.Nov 28 2022, 2:48 AM

tweak whitespace and */ behavior

hokein accepted this revision.Nov 28 2022, 4:19 AM

Thanks!

This revision is now accepted and ready to land.Nov 28 2022, 4:19 AM
This revision was landed with ongoing or failed builds.Nov 28 2022, 4:21 AM
This revision was automatically updated to reflect the committed changes.

Looks like it breaks the build:

llvm-project/clang-tools-extra/clangd/index/CanonicalIncludes.cpp: In member function ‘virtual bool clang::clangd::collectIWYUHeaderMaps(clang::clangd::CanonicalIncludes*)::PragmaCommentHandler::HandleComment(clang::Preprocessor&, clang::SourceRange)’:
llvm-project/clang-tools-extra/clangd/index/CanonicalIncludes.cpp:713:21: error: ‘parseIWYUPragma’ was not declared in this scope
       auto Pragma = parseIWYUPragma(
                     ^~~~~~~~~~~~~~~

Looks like it breaks the build:

llvm-project/clang-tools-extra/clangd/index/CanonicalIncludes.cpp: In member function ‘virtual bool clang::clangd::collectIWYUHeaderMaps(clang::clangd::CanonicalIncludes*)::PragmaCommentHandler::HandleComment(clang::Preprocessor&, clang::SourceRange)’:
llvm-project/clang-tools-extra/clangd/index/CanonicalIncludes.cpp:713:21: error: ‘parseIWYUPragma’ was not declared in this scope
       auto Pragma = parseIWYUPragma(
                     ^~~~~~~~~~~~~~~

Sorry, this is fixed in 551c7e81891abcf49aff625187f348ff119c4618 (I was running tests in the wrong terminal...)