Skip to content

Commit 009faee

Browse files
authored
Merge pull request #7061 from DavidGoldman/swift/release/5.9
[lldb] Fix ApplyWorkingDir not properly handling . includes when working dir is .
2 parents 514fa5f + 3a98889 commit 009faee

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,10 @@ void SwiftASTContext::ApplyWorkingDir(
15811581
llvm::SmallString<128> joined_path;
15821582
llvm::sys::path::append(joined_path, cur_working_dir, arg);
15831583
llvm::sys::path::remove_dots(joined_path);
1584+
// remove_dots can return an empty string if given a . or chain of ./.
1585+
if (joined_path.empty())
1586+
joined_path = ".";
1587+
15841588
clang_argument.resize(prefix.size());
15851589
clang_argument.append(joined_path.begin(), joined_path.end());
15861590
}

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
8282
TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
8383
std::string abs_working_dir = "/abs/dir";
8484
std::string rel_working_dir = "rel/dir";
85+
std::string dot_working_dir = ".";
8586

8687
// non-include option should not apply working dir
8788
llvm::SmallString<128> non_include_flag("-non-include-flag");
@@ -154,6 +155,16 @@ TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
154155
EXPECT_EQ(module_file_with_name_rel_path,
155156
llvm::SmallString<128>(
156157
"-fmodule-file=modulename=/abs/dir/relpath/module.pcm"));
158+
159+
// include path arg with cwd = .
160+
llvm::SmallString<128> dot_rel_path("-iquoterel/path");
161+
SwiftASTContext::ApplyWorkingDir(dot_rel_path, dot_working_dir);
162+
EXPECT_EQ(dot_rel_path, llvm::SmallString<128>("-iquoterel/path"));
163+
164+
// . include path arg with cwd = . should stay as .
165+
llvm::SmallString<128> dot_dot_path("-iquote.");
166+
SwiftASTContext::ApplyWorkingDir(dot_dot_path, dot_working_dir);
167+
EXPECT_EQ(dot_dot_path, llvm::SmallString<128>("-iquote."));
157168
}
158169

159170
namespace {

0 commit comments

Comments
 (0)