From 737c43a9e54a420978f7de88f445c311d47cc1e3 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Mon, 5 May 2025 09:12:11 -0700 Subject: [PATCH] [lldb] Fix swift debugging with swift-extra-clang-flags When the ClangImporter in SwiftASTContext is setup with DirectCC1, it wasn't working with `swift-extra-clang-flags` because that will trigger the non DirectCC1 code path only. Make the option working with DirectCC1 mode by directly appending the flag. rdar://150238095 --- .../Plugins/TypeSystem/Swift/SwiftASTContext.cpp | 14 ++++++++++++-- .../caching/TestSwiftClangImporterCaching.py | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 1ae044814f8e2..1430410bc85b7 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -1954,10 +1954,20 @@ void SwiftASTContext::AddExtraClangCC1Args( void SwiftASTContext::AddUserClangArgs(TargetProperties &props) { Args args(props.GetSwiftExtraClangFlags()); + if (args.empty()) + return; + std::vector user_clang_flags; - for (const auto &arg : args.entries()) + for (const auto &arg : args.entries()) { + if (arg.ref() == "--") + continue; user_clang_flags.push_back(arg.ref().str()); - AddExtraClangArgs(user_clang_flags, {}, {}); + } + if (GetClangImporterOptions().DirectClangCC1ModuleBuild) { + llvm::append_range(GetClangImporterOptions().ExtraArgs, user_clang_flags); + } else { + AddExtraClangArgs(user_clang_flags, {}, {}); + } } /// Turn relative paths in clang options into absolute paths based on diff --git a/lldb/test/API/lang/swift/clangimporter/caching/TestSwiftClangImporterCaching.py b/lldb/test/API/lang/swift/clangimporter/caching/TestSwiftClangImporterCaching.py index 90d5ad7461ec0..51992dd3cdbb5 100644 --- a/lldb/test/API/lang/swift/clangimporter/caching/TestSwiftClangImporterCaching.py +++ b/lldb/test/API/lang/swift/clangimporter/caching/TestSwiftClangImporterCaching.py @@ -20,6 +20,7 @@ def test(self): lldb.SBFileSpec('main.swift')) log = self.getBuildArtifact("types.log") self.runCmd("settings set target.swift-clang-override-options +-DADDED=1") + self.runCmd("settings set target.swift-extra-clang-flags -- -DEXTRA=1") self.expect('log enable lldb types -f "%s"' % log) self.expect("expression obj", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["b ="]) @@ -34,6 +35,7 @@ def test(self): # CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- -F # CHECK-NEXT: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- /FRAMEWORK_DIR # CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- -DADDED=1 +# CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- -DEXTRA=1 # CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift") Module import remark: loaded module 'ClangA' # CHECK-NOT: -cc1 # CHECK-NOT: -fmodule-file-cache-key