forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 344
Precise compiler invocations: Set C++ interoperability per SymbolContext #8592
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
Merged
adrian-prantl
merged 1 commit into
swiftlang:swift/release/6.0
from
adrian-prantl:125182583
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2172,6 +2172,41 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module, | |
return swift_ast_sp; | ||
} | ||
|
||
/// Determine whether this CU was compiled with C++ interop enabled. | ||
static bool ShouldEnableCXXInterop(CompileUnit *cu) { | ||
AutoBool interop_enabled = | ||
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop(); | ||
switch (interop_enabled) { | ||
case AutoBool::True: | ||
return true; | ||
case AutoBool::False: | ||
return false; | ||
case AutoBool::Auto: { | ||
if (!cu) | ||
return false; | ||
lldb::ModuleSP module = cu->CalculateSymbolContextModule(); | ||
if (!module) | ||
return false; | ||
// Look for the "-enable-experimental-cxx-interop" compile flag in the | ||
// args of the compile units this module is composed of. | ||
auto *sym_file = module->GetSymbolFile(); | ||
if (!sym_file) | ||
return false; | ||
auto options = sym_file->GetCompileOptions(); | ||
for (auto &[unit, args] : options) { | ||
if (unit.get() == cu) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (cu->GetLanguage() == eLanguageTypeSwift) | ||
for (const char *arg : args.GetArgumentArrayRef()) | ||
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0) | ||
return true; | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
static bool IsUnitTestExecutable(lldb_private::Module &module) { | ||
static ConstString s_xctest("xctest"); | ||
static ConstString s_XCTRunner("XCTRunner"); | ||
|
@@ -2728,7 +2763,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance( | |
swift_ast_sp->m_is_scratch_context = true; | ||
|
||
swift_ast_sp->GetLanguageOptions().EnableCXXInterop = | ||
target.IsSwiftCxxInteropEnabled(); | ||
ShouldEnableCXXInterop(cu); | ||
|
||
if (target.IsEmbeddedSwift()) | ||
swift_ast_sp->GetLanguageOptions().enableFeature(swift::Feature::Embedded); | ||
|
3 changes: 3 additions & 0 deletions
3
lldb/test/API/lang/swift/cxx_interop/forward/langopt/Dylib.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public func f() { | ||
print("break here") | ||
} |
21 changes: 21 additions & 0 deletions
21
lldb/test/API/lang/swift/cxx_interop/forward/langopt/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
SWIFT_SOURCES := main.swift | ||
SWIFT_CXX_INTEROP := 1 | ||
SWIFTFLAGS_EXTRAS = -I. | ||
LD_EXTRAS = -L$(BUILDDIR) -lDylib | ||
|
||
all: libDylib.dylib a.out | ||
|
||
include Makefile.rules | ||
|
||
libDylib.dylib: Dylib.swift | ||
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \ | ||
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \ | ||
VPATH=$(SRCDIR) -I $(SRCDIR) \ | ||
-f $(THIS_FILE_DIR)/Makefile.rules \ | ||
DYLIB_SWIFT_SOURCES=Dylib.swift \ | ||
DYLIB_NAME=Dylib \ | ||
DYLIB_ONLY=YES \ | ||
SWIFT_SOURCES= \ | ||
SWIFT_CXX_INTEROP=0 \ | ||
SWIFT_BRIDGING_HEADER= \ | ||
all |
32 changes: 32 additions & 0 deletions
32
lldb/test/API/lang/swift/cxx_interop/forward/langopt/TestSwiftForwardInteropCxxLangOpt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
""" | ||
Test that a C++ class is visible in Swift. | ||
""" | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test.decorators import * | ||
|
||
|
||
class TestSwiftForwardInteropCxxLangOpt(TestBase): | ||
|
||
@swiftTest | ||
@expectedFailureAll(setting=('symbols.swift-precise-compiler-invocation', 'false')) | ||
def test_class(self): | ||
""" | ||
Test that C++ interoperability is enabled on a per-CU basis. | ||
""" | ||
self.build() | ||
log = self.getBuildArtifact("types.log") | ||
self.runCmd('log enable lldb types -f "%s"' % log) | ||
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
self, 'break here', lldb.SBFileSpec('main.swift'), | ||
extra_images=['Dylib']) | ||
dylib_bkpt = target.BreakpointCreateBySourceRegex( | ||
'break here', lldb.SBFileSpec('Dylib.swift')) | ||
self.assertGreater(dylib_bkpt.GetNumLocations(), 0, VALID_BREAKPOINT) | ||
self.expect('expr 0') | ||
lldbutil.continue_to_breakpoint(process, dylib_bkpt) | ||
self.expect('expr 1') | ||
self.filecheck('platform shell cat ""%s"' % log, __file__) | ||
# CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration(){{.*}}Swift/C++ interop : on | ||
# CHECK: SwiftASTContextForExpressions(module: "Dylib", cu: "Dylib.swift")::LogConfiguration(){{.*}}Swift/C++ interop : off | ||
|
10 changes: 10 additions & 0 deletions
10
lldb/test/API/lang/swift/cxx_interop/forward/langopt/bridging.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
struct CxxClass { | ||
long long a1 = 10; | ||
long long a2 = 20; | ||
long long a3 = 30; | ||
}; | ||
|
||
struct InheritedCxxClass: CxxClass { | ||
long long a4 = 40; | ||
}; |
4 changes: 4 additions & 0 deletions
4
lldb/test/API/lang/swift/cxx_interop/forward/langopt/main.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Dylib | ||
|
||
print("break here") | ||
f() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you call
Module::IsSwiftCxxInteropEnabled
? The code looks pretty much the same.