Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb][swift] Ignore -- flag in swift-extra-clang-flags #2407

Open
wants to merge 1 commit into
base: swift/next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,15 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string>& source,
if (clang_argument.startswith("-Werror"))
continue;

// Drop `--`. This might be coming from the user-provided setting
// swift-extra-clang-flags (where users sometimes think a -- is necessary
// to separate the flags from the settings name). `--` indicates to Clang
// that all following arguments are file names instead of flags, so this
// should never be passed to Clang (which would otherwise either crash or
// cause Clang to look for files with the name '-Wflag-name`).
if (clang_argument == "--")
continue;

if (clang_argument.empty())
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ def test_extra_clang_flags(self):
lldb.SBFileSpec('main.swift'))
self.expect("frame var foo", "sanity check", substrs=['(Foo)'])
self.expect("expr FromOverlay(i: 23)", substrs=['(FromOverlay)', '23'])

# Don't run ClangImporter tests if Clangimporter is disabled.
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
@skipIf(oslist=['windows'])
@swiftTest
def test_invalid_extra_clang_flags(self):
"""
Test that LLDB ignores specific invalid arguments in
swift-extra-clang-flags.
"""
self.build()
self.addTearDownHook(
lambda: self.runCmd("settings clear target.swift-extra-clang-flags"))

self.expect('settings set target.swift-extra-clang-flags -- -v')

lldbutil.run_to_source_breakpoint(self, "break here",
lldb.SBFileSpec('main.swift'))
self.expect("frame var foo", substrs=['(Foo)'])
10 changes: 10 additions & 0 deletions lldb/unittests/Symbol/TestSwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,13 @@ TEST(ClangArgs, UniquingCollisionWithAddedFlags) {

EXPECT_EQ(dest, uniqued_flags);
}

TEST(ClangArgs, DoubleDash) {
// -v with all currently ignored arguments following.
const std::vector<std::string> source{"-v", "--", "-Werror", ""};
std::vector<std::string> dest;
SwiftASTContext::AddExtraClangArgs(source, dest);

// Check that all ignored arguments got removed.
EXPECT_EQ(dest, std::vector<std::string>({"-v"}));
}