Skip to content

Commit 97f9e4e

Browse files
committed
Don't pass -Werror to ClangImporter's clang when Swift is used from within LLDB.
This works a around search path problems caused by a module existing in both the build/install directory and the source directory. <rdar://problem/35714074>
1 parent 18815fb commit 97f9e4e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class ClangImporterOptions {
9797
/// When set, don't look for or load adapter modules.
9898
bool DisableAdapterModules = false;
9999

100+
/// When set, don't enforce warnings with -Werror.
101+
bool DebuggerSupport = false;
102+
100103
/// Return a hash code of any components from these options that should
101104
/// contribute to a Swift Bridging PCH hash.
102105
llvm::hash_code getPCHHashComponents() const {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,6 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
446446
// Construct the invocation arguments for the current target.
447447
// Add target-independent options first.
448448
invocationArgStrs.insert(invocationArgStrs.end(), {
449-
// Enable modules
450-
"-fmodules",
451-
"-Werror=non-modular-include-in-framework-module",
452-
"-Xclang", "-fmodule-feature", "-Xclang", "swift",
453-
454449
// Don't emit LLVM IR.
455450
"-fsyntax-only",
456451

@@ -464,6 +459,18 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
464459
SHIMS_INCLUDE_FLAG, searchPathOpts.RuntimeResourcePath,
465460
});
466461

462+
// Enable modules.
463+
invocationArgStrs.insert(invocationArgStrs.end(), {
464+
"-fmodules",
465+
"-Xclang", "-fmodule-feature", "-Xclang", "swift"
466+
});
467+
// Don't enforce strict rules when inside the debugger to work around search
468+
// path problems caused by a module existing in both the build/install
469+
// directory and the source directory.
470+
if (!importerOpts.DebuggerSupport)
471+
invocationArgStrs.push_back(
472+
"-Werror=non-modular-include-in-framework-module");
473+
467474
if (LangOpts.EnableObjCInterop) {
468475
invocationArgStrs.insert(invocationArgStrs.end(),
469476
{"-x", "objective-c", "-std=gnu11", "-fobjc-arc"});

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
12341234
Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation);
12351235
}
12361236

1237+
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
12371238
return false;
12381239
}
12391240

test/ClangImporter/non-modular-include.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
// CHECK-native: error: could not build C module 'Foo'
77
// CHECK-NOT: error
88

9+
// RUN: %target-swift-frontend -debugger-support -typecheck %s -I %S/Inputs/non-modular -F %S/Inputs/non-modular 2>&1 | %FileCheck --allow-empty --check-prefix=CHECK-DEBUGGER %s
10+
11+
// CHECK-DEBUGGER-NOT: error:
12+
13+
914
import Foo
1015

1116
_ = Foo.x

0 commit comments

Comments
 (0)