Skip to content

Commit 1999ae9

Browse files
Merge pull request swiftlang#7152 from adrian-prantl/cherry-pick-20230725
Cherry pick 20230725
2 parents 6f07dae + bd4dfb9 commit 1999ae9

File tree

8 files changed

+88
-1
lines changed

8 files changed

+88
-1
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,10 +874,12 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
874874
needs_init = true;
875875

876876
Status error;
877-
878877
if (repl) {
879878
if (!variable.GetType().IsVoidType()) {
880879
auto &repl_mat = *llvm::cast<SwiftREPLMaterializer>(&materializer);
880+
assert(variable.GetType()
881+
.GetTypeSystem()
882+
.isa_and_nonnull<TypeSystemSwiftTypeRef>());
881883
offset = repl_mat.AddREPLResultVariable(
882884
variable.GetType(), variable.GetDecl(),
883885
is_result ? &user_expression.GetResultDelegate()
@@ -909,6 +911,8 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
909911
ToCompilerType(transformed_type->mapTypeOutOfContext().getPointer());
910912
auto swift_ast_ctx =
911913
actual_type.GetTypeSystem().dyn_cast_or_null<SwiftASTContext>();
914+
if (!swift_ast_ctx)
915+
return {};
912916

913917
actual_type =
914918
swift_ast_ctx->GetTypeRefType(actual_type.GetOpaqueQualType());

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,10 @@ void SwiftASTContext::ApplyWorkingDir(
15861586
llvm::SmallString<128> joined_path;
15871587
llvm::sys::path::append(joined_path, cur_working_dir, arg);
15881588
llvm::sys::path::remove_dots(joined_path);
1589+
// remove_dots can return an empty string if given a . or chain of ./.
1590+
if (joined_path.empty())
1591+
joined_path = ".";
1592+
15891593
clang_argument.resize(prefix.size());
15901594
clang_argument.append(joined_path.begin(), joined_path.end());
15911595
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo(_ x : Int) -> Int {
2+
return x + x
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFT_OBJC_INTEROP := 1
3+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
4+
LD_EXTRAS = -L$(BUILDDIR) -lFoo
5+
6+
all: libFoo.dylib $(EXE)
7+
8+
include Makefile.rules
9+
10+
OVERLAY := $(BUILDDIR)/overlay.yaml
11+
lib%.dylib: %.swift
12+
echo "struct S {};">$(BUILDDIR)/header.h
13+
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
14+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
15+
BASENAME=$(shell basename $< .swift) \
16+
SWIFT_BRIDGING_HEADER=header.h \
17+
SWIFT_PRECOMPILE_BRIDGING_HEADER=YES \
18+
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all
19+
rm -f $(OVERLAY)
20+
21+
clean::
22+
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
23+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
24+
BASENAME=$(shell basename $< .swift) \
25+
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
import os
7+
8+
class TestSwiftMissingVFSOverlay(TestBase):
9+
mydir = TestBase.compute_mydir(__file__)
10+
11+
NO_DEBUG_INFO_TESTCASE = True
12+
13+
def setUp(self):
14+
TestBase.setUp(self)
15+
16+
# Don't run ClangImporter tests if Clangimporter is disabled.
17+
@skipIf(setting=("symbols.use-swift-clangimporter", "false"))
18+
@skipUnlessDarwin
19+
@swiftTest
20+
def test(self):
21+
"""This used to be a test for a diagnostic, however,
22+
this is no longer an unrecoverable error"""
23+
self.build()
24+
os.unlink(self.getBuildArtifact("header.pch"))
25+
lldbutil.run_to_source_breakpoint(
26+
self, "break here", lldb.SBFileSpec("main.swift"),
27+
extra_images=["Foo"]
28+
)
29+
# FIXME: This crashes the compiler while trying to diagnose the
30+
# missing file (because the source location is inside the missing file).
31+
#self.expect("expr y", substrs=["1"])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DYLIB_ONLY := YES
2+
DYLIB_NAME := $(BASENAME)
3+
DYLIB_SWIFT_SOURCES := $(DYLIB_NAME).swift
4+
5+
include Makefile.rules
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Foo
2+
3+
let y = foo(21)
4+
print(y) // break here

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
8383
TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
8484
std::string abs_working_dir = "/abs/dir";
8585
std::string rel_working_dir = "rel/dir";
86+
std::string dot_working_dir = ".";
8687

8788
// non-include option should not apply working dir
8889
llvm::SmallString<128> non_include_flag("-non-include-flag");
@@ -155,6 +156,16 @@ TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
155156
EXPECT_EQ(module_file_with_name_rel_path,
156157
llvm::SmallString<128>(
157158
"-fmodule-file=modulename=/abs/dir/relpath/module.pcm"));
159+
160+
// include path arg with cwd = .
161+
llvm::SmallString<128> dot_rel_path("-iquoterel/path");
162+
SwiftASTContext::ApplyWorkingDir(dot_rel_path, dot_working_dir);
163+
EXPECT_EQ(dot_rel_path, llvm::SmallString<128>("-iquoterel/path"));
164+
165+
// . include path arg with cwd = . should stay as .
166+
llvm::SmallString<128> dot_dot_path("-iquote.");
167+
SwiftASTContext::ApplyWorkingDir(dot_dot_path, dot_working_dir);
168+
EXPECT_EQ(dot_dot_path, llvm::SmallString<128>("-iquote."));
158169
}
159170

160171
TEST_F(TestSwiftASTContext, PluginPath) {

0 commit comments

Comments
 (0)