Skip to content

Commit 8fc7a90

Browse files
committed
Let normalize() for posix style convert backslash to slash unconditionally.
Currently, normalize() for posix replaces backslashes to slashes, except that two backslashes in sequence are kept as-is. clang calls normalize() to convert \ to / is microsoft compat mode. This generally works well, but a path like "c:\\foo\\bar.h" with two backslashes doesn't work due to the exception in normalize(). These paths happen naturally on Windows hosts with e.g. `#include __FILE__`, and them not working on other hosts makes it more difficult to write tests for this case. The special case has been around without justification since this code was added in r203611 (since then moved around in r215241 r215243). No integration tests fail if I remove it. Try removing the special case. Differential Revision: https://reviews.llvm.org/D79265
1 parent 93d1108 commit 8fc7a90

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

clang/test/Lexer/case-insensitive-include-ms.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
// RUN: %clang_cc1 -fsyntax-only -fms-compatibility %s -include %s -I %t/Output -verify
77
// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -fdiagnostics-parseable-fixits %s -include %s -I %t/Output 2>&1 | FileCheck %s
88

9-
// FIXME: Add a test with repeated backslashes once clang can handle that
10-
// in ms-compat mode on non-Windows hosts.
119
#include "..\Output\.\case-insensitive-include.h"
1210
#include "..\Output\.\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
1311
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"..\\Output\\.\\case-insensitive-include.h\""
12+
#include "..\\Output\.\\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
13+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:52}:"\"..\\\\Output\\.\\\\case-insensitive-include.h\""
1414
#include "..\output\.\case-insensitive-include.h" // expected-warning {{non-portable path}}
1515
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"..\\Output\\.\\case-insensitive-include.h\""
1616

1717
#include "apath\..\.\case-insensitive-include.h"
1818
#include "apath\..\.\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
1919
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:49}:"\"apath\\..\\.\\case-insensitive-include.h\""
20+
#include "apath\\..\\.\\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
21+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:52}:"\"apath\\\\..\\\\.\\\\case-insensitive-include.h\""
2022
#include "APath\..\.\case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(

llvm/lib/Support/Path.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,9 @@ void native(SmallVectorImpl<char> &Path, Style style) {
540540
Path = PathHome;
541541
}
542542
} else {
543-
for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI) {
544-
if (*PI == '\\') {
545-
auto PN = PI + 1;
546-
if (PN < PE && *PN == '\\')
547-
++PI; // increment once, the for loop will move over the escaped slash
548-
else
549-
*PI = '/';
550-
}
551-
}
543+
for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI)
544+
if (*PI == '\\')
545+
*PI = '/';
552546
}
553547
}
554548

llvm/unittests/Support/Path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ TEST(Support, NormalizePath) {
11821182
Tests.emplace_back("a", "a", "a");
11831183
Tests.emplace_back("a/b", "a\\b", "a/b");
11841184
Tests.emplace_back("a\\b", "a\\b", "a/b");
1185-
Tests.emplace_back("a\\\\b", "a\\\\b", "a\\\\b");
1185+
Tests.emplace_back("a\\\\b", "a\\\\b", "a//b");
11861186
Tests.emplace_back("\\a", "\\a", "/a");
11871187
Tests.emplace_back("a\\", "a\\", "a/");
11881188
Tests.emplace_back("a\\t", "a\\t", "a/t");

0 commit comments

Comments
 (0)