aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
diff options
context:
space:
mode:
authorSalman Javed <mail@salmanjaved.org>2021-11-10 18:34:41 +1300
committerSalman Javed <mail@salmanjaved.org>2021-11-10 18:35:57 +1300
commitb4f6f1c9369ec4bb1c10852283a8c7e8c39e1a8d (patch)
tree1c749c29defbae5fe1e720f6c72ab439a2e63e63 /clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
parent577c1eecf8c4b078eecb57e1c5b8d86adfc3c08a (diff)
downloadllvm-b4f6f1c9369ec4bb1c10852283a8c7e8c39e1a8d.zip
llvm-b4f6f1c9369ec4bb1c10852283a8c7e8c39e1a8d.tar.gz
llvm-b4f6f1c9369ec4bb1c10852283a8c7e8c39e1a8d.tar.bz2
[clang-tidy] Fix llvm-header-guard so that it works with Windows paths
Fixes pr40372 (https://bugs.llvm.org/show_bug.cgi?id=40372). The llvm-header-guard check does not take into account that the path separator on Windows is `\`, not `/`. This means that instead of suggesting a header guard in the form of: LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FOO_H it incorrectly suggests: C:\LLVM_PROJECT\CLANG_TOOLS_EXTRA\CLANG_TIDY\FOO_H Differential Revision: https://reviews.llvm.org/D113450
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
index 8f8bd7a..53c1e3c 100644
--- a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
@@ -8,6 +8,7 @@
#include "HeaderGuardCheck.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Path.h"
namespace clang {
namespace tidy {
@@ -21,6 +22,10 @@ std::string LLVMHeaderGuardCheck::getHeaderGuard(StringRef Filename,
StringRef OldGuard) {
std::string Guard = tooling::getAbsolutePath(Filename);
+ // When running under Windows, need to convert the path separators from
+ // `\` to `/`.
+ Guard = llvm::sys::path::convert_to_slash(Guard);
+
// Sanitize the path. There are some rules for compatibility with the historic
// style in include/llvm and include/clang which we want to preserve.