[PATCH] D68026: [clangd] Add missing header guard, NFC.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 25 07:25:07 PDT 2019
hokein updated this revision to Diff 221765.
hokein added a comment.
upload correct diff.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68026/new/
https://reviews.llvm.org/D68026
Files:
clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -211,6 +211,15 @@
"#endif /* LLVM_ADT_FOO_H\\ \n"
" FOO */",
"include/llvm/ADT/foo.h", None));
+
+ EXPECT_EQ("#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FOO_H\n"
+ "#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FOO_H\n"
+ "\n"
+ "\n"
+ "#endif\n",
+ runHeaderGuardCheck(
+ "", "/llvm-project/clang-tools-extra/clangd/foo.h",
+ StringRef("header is missing header guard")));
}
#endif
Index: clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
+++ clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
@@ -33,6 +33,13 @@
if (PosToolsClang != StringRef::npos)
Guard = Guard.substr(PosToolsClang + std::strlen("tools/"));
+ // Unlike LLVM svn, LLVM git monorepo is named llvm-project, so we replace
+ // "/llvm-project/" with the cannonical "/llvm/".
+ const static StringRef LLVMProject = "/llvm-project/";
+ size_t PosLLVMProject = Guard.rfind(LLVMProject);
+ if (PosLLVMProject != StringRef::npos)
+ Guard = Guard.replace(PosLLVMProject, LLVMProject.size(), "/llvm/");
+
// The remainder is LLVM_FULL_PATH_TO_HEADER_H
size_t PosLLVM = Guard.rfind("llvm/");
if (PosLLVM != StringRef::npos)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68026.221765.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190925/8147f040/attachment.bin>
More information about the cfe-commits
mailing list