summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-10-27 15:57:48 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-10-27 15:57:48 +0200
commit2db621da6660d56f3ff1954adf4ed8ce71834bf6 (patch)
tree821e378aa65e5dd99718247f7b908bdc053a2020 /compilerplugins
parentaace85877c85935bbe92ecdfc1c27271b89628e5 (diff)
Adapt loplugin:includeform to Windows \ path separator
This can also call loplugin::isSamePathname with two paths that both contain backslashes, so finally make it (and hasPathnamePrefix) symmetric in which arguments my contain backslashes. Change-Id: I0465988d9d41e21c5660cbdbd1558543860ae1ad
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/includeform.cxx11
-rw-r--r--compilerplugins/clang/plugin.cxx29
-rw-r--r--compilerplugins/clang/plugin.hxx8
3 files changed, 35 insertions, 13 deletions
diff --git a/compilerplugins/clang/includeform.cxx b/compilerplugins/clang/includeform.cxx
index b3ab195fbe09..11bf2865c58c 100644
--- a/compilerplugins/clang/includeform.cxx
+++ b/compilerplugins/clang/includeform.cxx
@@ -52,7 +52,16 @@ private:
auto const file = StringRef(
compiler.getSourceManager().getPresumedLoc(HashLoc)
.getFilename());
- auto const dir = compat::take_front(file, file.rfind('/'));
+ auto pos = file.rfind('/');
+#if defined _WIN32
+ auto const pos2 = file.rfind('\\');
+ if (pos2 != StringRef::npos
+ && (pos == StringRef::npos || pos2 > pos))
+ {
+ pos = pos2;
+ }
+#endif
+ auto const dir = compat::take_front(file, pos);
shouldUseAngles = !loplugin::isSamePathname(SearchPath, dir);
}
if (shouldUseAngles == IsAngled) {
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 077b24370f71..7d53e71dfd61 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -442,15 +442,28 @@ template<typename Fn> bool checkPathname(
for (std::size_t n = 0;;)
{
std::size_t n1 = pathname.find('\\', n);
- if (n1 >= against.size()) {
- return check(pathname.substr(n), against.substr(n));
- }
- if (against[n1] != '/'
- || pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
- {
- break;
+ std::size_t n2 = against.find('\\', n);
+ if (n1 <= n2) {
+ if (n1 >= against.size()) {
+ return check(pathname.substr(n), against.substr(n));
+ }
+ if ((against[n1] != '/' && against[n1] != '\\')
+ || pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
+ {
+ break;
+ }
+ n = n1 + 1;
+ } else {
+ if (n2 >= pathname.size()) {
+ return check(pathname.substr(n), against.substr(n));
+ }
+ if (pathname[n2] != '/'
+ || pathname.substr(n, n2 - n) != against.substr(n, n2 - n))
+ {
+ break;
+ }
+ n = n2 + 1;
}
- n = n1 + 1;
}
#endif
return false;
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 1f57dfeb0ffa..89d9999255df 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -215,12 +215,12 @@ RewritePlugin::RewriteOption operator|( RewritePlugin::RewriteOption option1, Re
return static_cast< RewritePlugin::RewriteOption >( int( option1 ) | int( option2 ));
}
-// Same as pathname.startswith(prefix), except on Windows, where pathname (but
-// not prefix) may also contain backslashes:
+// Same as pathname.startswith(prefix), except on Windows, where pathname and
+// prefix may also contain backslashes:
bool hasPathnamePrefix(StringRef pathname, StringRef prefix);
-// Same as pathname == other, except on Windows, where pathname (but not other)
-// may also contain backslashes:
+// Same as pathname == other, except on Windows, where pathname and other may
+// also contain backslashes:
bool isSamePathname(StringRef pathname, StringRef other);
} // namespace