From 08233a505fa7c54830c6a70d4da88b007e8cfca8 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Tue, 7 Jan 2025 17:17:51 -0800 Subject: [PATCH] [lldb] Add an expression evaluation test for modules built with -enable-testing and -enable-library-evolution -enable-testing affects the visibility of types, which together with -enable-library-evolution may cause the compiler embedded in LLDB to generate incorrect code on expression evaluation. --- .../API/lang/swift/enable_testing/Makefile | 22 +++++++++++++++++++ .../lang/swift/enable_testing/Public.swift | 15 +++++++++++++ .../enable_testing/TestSwiftEnableTesting.py | 21 ++++++++++++++++++ .../API/lang/swift/enable_testing/main.swift | 3 +++ 4 files changed, 61 insertions(+) create mode 100644 lldb/test/API/lang/swift/enable_testing/Makefile create mode 100644 lldb/test/API/lang/swift/enable_testing/Public.swift create mode 100644 lldb/test/API/lang/swift/enable_testing/TestSwiftEnableTesting.py create mode 100644 lldb/test/API/lang/swift/enable_testing/main.swift diff --git a/lldb/test/API/lang/swift/enable_testing/Makefile b/lldb/test/API/lang/swift/enable_testing/Makefile new file mode 100644 index 00000000000000..7417fa8d4aaf20 --- /dev/null +++ b/lldb/test/API/lang/swift/enable_testing/Makefile @@ -0,0 +1,22 @@ +SWIFT_SOURCES := main.swift + +all: libPublic.dylib a.out + +include Makefile.rules +LD_EXTRAS = -lPublic -L$(BUILDDIR) +SWIFTFLAGS_EXTRAS = -I$(BUILDDIR) + +libPublic.dylib: Public.swift + "$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \ + ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \ + BASENAME=Public \ + SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution -enable-testing" \ + VPATH=$(SRCDIR) -I $(SRCDIR) \ + DYLIB_ONLY:=YES DYLIB_NAME=Public \ + DYLIB_SWIFT_SOURCES:=Public.swift \ + -f $(MAKEFILE_RULES) + +clean:: + "$(MAKE)" BASENAME=Public VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean + + diff --git a/lldb/test/API/lang/swift/enable_testing/Public.swift b/lldb/test/API/lang/swift/enable_testing/Public.swift new file mode 100644 index 00000000000000..a5224ad2e52f74 --- /dev/null +++ b/lldb/test/API/lang/swift/enable_testing/Public.swift @@ -0,0 +1,15 @@ +class SomeClass { + let value = 42 +} + +class ClassWithProperty { + private var v = SomeClass() + + func f() { + print("break here") + } +} + +public func entry() { + ClassWithProperty().f() +} diff --git a/lldb/test/API/lang/swift/enable_testing/TestSwiftEnableTesting.py b/lldb/test/API/lang/swift/enable_testing/TestSwiftEnableTesting.py new file mode 100644 index 00000000000000..a6af1d5662ef8b --- /dev/null +++ b/lldb/test/API/lang/swift/enable_testing/TestSwiftEnableTesting.py @@ -0,0 +1,21 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestSwiftEnableTesting(TestBase): + + def setUp(self): + TestBase.setUp(self) + + @swiftTest + def test(self): + """Test that expression evaluation generates a direct member access to a private property in a module compiled with -enable-library-evolution and -enable-testing""" + + self.build() + target, process, _, _ = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("Public.swift"), extra_images=["Public"] + ) + + self.expect("expression v", substrs=["Public.SomeClass", "value = 42"]) diff --git a/lldb/test/API/lang/swift/enable_testing/main.swift b/lldb/test/API/lang/swift/enable_testing/main.swift new file mode 100644 index 00000000000000..839650f1559371 --- /dev/null +++ b/lldb/test/API/lang/swift/enable_testing/main.swift @@ -0,0 +1,3 @@ +import Public + +entry()