Skip to content

Cherry pick 20230725 #7152

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
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,12 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
needs_init = true;

Status error;

if (repl) {
if (!variable.GetType().IsVoidType()) {
auto &repl_mat = *llvm::cast<SwiftREPLMaterializer>(&materializer);
assert(variable.GetType()
.GetTypeSystem()
.isa_and_nonnull<TypeSystemSwiftTypeRef>());
offset = repl_mat.AddREPLResultVariable(
variable.GetType(), variable.GetDecl(),
is_result ? &user_expression.GetResultDelegate()
Expand Down Expand Up @@ -909,6 +911,8 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
ToCompilerType(transformed_type->mapTypeOutOfContext().getPointer());
auto swift_ast_ctx =
actual_type.GetTypeSystem().dyn_cast_or_null<SwiftASTContext>();
if (!swift_ast_ctx)
return {};

actual_type =
swift_ast_ctx->GetTypeRefType(actual_type.GetOpaqueQualType());
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,10 @@ void SwiftASTContext::ApplyWorkingDir(
llvm::SmallString<128> joined_path;
llvm::sys::path::append(joined_path, cur_working_dir, arg);
llvm::sys::path::remove_dots(joined_path);
// remove_dots can return an empty string if given a . or chain of ./.
if (joined_path.empty())
joined_path = ".";

clang_argument.resize(prefix.size());
clang_argument.append(joined_path.begin(), joined_path.end());
}
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/missing_pch/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func foo(_ x : Int) -> Int {
return x + x
}
25 changes: 25 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/missing_pch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
SWIFT_SOURCES := main.swift
SWIFT_OBJC_INTEROP := 1
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
LD_EXTRAS = -L$(BUILDDIR) -lFoo

all: libFoo.dylib $(EXE)

include Makefile.rules

OVERLAY := $(BUILDDIR)/overlay.yaml
lib%.dylib: %.swift
echo "struct S {};">$(BUILDDIR)/header.h
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=$(shell basename $< .swift) \
SWIFT_BRIDGING_HEADER=header.h \
SWIFT_PRECOMPILE_BRIDGING_HEADER=YES \
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all
rm -f $(OVERLAY)

clean::
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=$(shell basename $< .swift) \
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2
import os

class TestSwiftMissingVFSOverlay(TestBase):
mydir = TestBase.compute_mydir(__file__)

NO_DEBUG_INFO_TESTCASE = True

def setUp(self):
TestBase.setUp(self)

# Don't run ClangImporter tests if Clangimporter is disabled.
@skipIf(setting=("symbols.use-swift-clangimporter", "false"))
@skipUnlessDarwin
@swiftTest
def test(self):
"""This used to be a test for a diagnostic, however,
this is no longer an unrecoverable error"""
self.build()
os.unlink(self.getBuildArtifact("header.pch"))
lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift"),
extra_images=["Foo"]
)
# FIXME: This crashes the compiler while trying to diagnose the
# missing file (because the source location is inside the missing file).
#self.expect("expr y", substrs=["1"])
5 changes: 5 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/missing_pch/dylib.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DYLIB_ONLY := YES
DYLIB_NAME := $(BASENAME)
DYLIB_SWIFT_SOURCES := $(DYLIB_NAME).swift

include Makefile.rules
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/missing_pch/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Foo

let y = foo(21)
print(y) // break here
11 changes: 11 additions & 0 deletions lldb/unittests/Symbol/TestSwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
std::string abs_working_dir = "/abs/dir";
std::string rel_working_dir = "rel/dir";
std::string dot_working_dir = ".";

// non-include option should not apply working dir
llvm::SmallString<128> non_include_flag("-non-include-flag");
Expand Down Expand Up @@ -155,6 +156,16 @@ TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
EXPECT_EQ(module_file_with_name_rel_path,
llvm::SmallString<128>(
"-fmodule-file=modulename=/abs/dir/relpath/module.pcm"));

// include path arg with cwd = .
llvm::SmallString<128> dot_rel_path("-iquoterel/path");
SwiftASTContext::ApplyWorkingDir(dot_rel_path, dot_working_dir);
EXPECT_EQ(dot_rel_path, llvm::SmallString<128>("-iquoterel/path"));

// . include path arg with cwd = . should stay as .
llvm::SmallString<128> dot_dot_path("-iquote.");
SwiftASTContext::ApplyWorkingDir(dot_dot_path, dot_working_dir);
EXPECT_EQ(dot_dot_path, llvm::SmallString<128>("-iquote."));
}

TEST_F(TestSwiftASTContext, PluginPath) {
Expand Down