This is an archive of the discontinued LLVM Phabricator instance.

[clangd] cleanup of header guard names
ClosedPublic

Authored by kuhnel on Nov 15 2021, 7:15 AM.

Details

Summary

Renaming header guards to match the LLVM convention.
This patch was created by automatically applying the fixes from
clang-tidy.

I've removed the [NFC] tag from the title, as we're adding header guards in some files and thus might trigger behavior changes.

Diff Detail

Event Timeline

kuhnel created this revision.Nov 15 2021, 7:15 AM
kuhnel published this revision for review.Nov 15 2021, 7:16 AM
kuhnel added subscribers: sammccall, adamcz, kbobyrev.

Mostly LG, just a few files are test inputs and one is empty

clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/foo.h
1 ↗(On Diff #387251)

Please don't modify tests, they don't need to follow LLVM style and should be as simple as possible

clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h
1 ↗(On Diff #387251)

In particular, adding header guards to test files without them isn't NFC

clang-tools-extra/clangd/unittests/TestScheme.h
1

What's up with this change?
If this file is empty it should just be deleted instead

kuhnel updated this revision to Diff 387929.Nov 17 2021, 6:34 AM
kuhnel marked 3 inline comments as done.

addresed Sam's comments

kuhnel retitled this revision from [NFC][clangd] cleanup of header guard names to [clangd] cleanup of header guard names.Nov 17 2021, 6:36 AM
kuhnel edited the summary of this revision. (Show Details)
kuhnel added inline comments.
clang-tools-extra/clangd/PathMapping.h
4

Looks like the include guards were missing here. I suppose this is something we want to add.

clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/foo.h
1 ↗(On Diff #387251)

I was iterating over all .cpp and .h files, so the test data ended up in the changes as well.

I suppose the only way to avoid this is to use the run-clang-tidy.py wraper script instead

clang-tools-extra/clangd/unittests/LSPClient.h
2

Same here. I suppose we want header guards in this one.

clang-tools-extra/clangd/unittests/TestScheme.h
1

Deleting the file

kbobyrev added inline comments.Dec 2 2021, 2:51 AM
clang-tools-extra/clangd/PathMapping.h
2

Please move the header guard after the comment like we do in the other files.

72

Please add a closing comment (// LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHMAPPING_H)

clang-tools-extra/clangd/unittests/LSPClient.h
1

Please move the header guard after the comment like we do in the other files.

87

Also needs a closing comment.

LG apart from closing comments, some of the files have it and some don't (apart from the newly introduced ones, it didn't add it to the files that didn't have a closing comment, but updated the ones that had).
The code from the tidy check looks like it should be handling this case, can you check what's going on?

kuhnel updated this revision to Diff 391301.Dec 2 2021, 6:15 AM
kuhnel marked 4 inline comments as done.

addressed review comments

kuhnel added a comment.Dec 2 2021, 6:15 AM

@kadircet looks like clang-tidy does not detect missing comments in #endif. It does complain about missing comments for namespaces. E.g. in Serialization.h the #endif comment is missing, but without a finding.

Also, please mention the

@kadircet looks like clang-tidy does not detect missing comments in #endif. It does complain about missing comments for namespaces. E.g. in Serialization.h the #endif comment is missing, but without a finding.

This looks to be a deliberate decision: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h#L32

Looking at the code under clang/include, it looks like most headers don't have the #endif // COMMENT, so this might be correct. However, the style guide is rather vague and doesn't mention this at all: https://llvm.org/docs/CodingStandards.html#header-guard

This revision was not accepted when it landed; it landed in state Needs Review.Dec 2 2021, 7:59 AM
This revision was automatically updated to reflect the committed changes.

This looks to be a deliberate decision: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h#L32

Looking at the code under clang/include, it looks like most headers don't have the #endif // COMMENT, so this might be correct. However, the style guide is rather vague and doesn't mention this at all: https://llvm.org/docs/CodingStandards.html#header-guard

ah right, I was looking at https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp#L289, which happens to be the base class. thanks!