Skip to content

Commit 4125cdd

Browse files
author
git apple-llvm automerger
committed
Merge commit '2848fe771932' from swift/release/5.5 into swift/main
2 parents 85b044d + 2848fe7 commit 4125cdd

File tree

9 files changed

+148
-55
lines changed

9 files changed

+148
-55
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,15 @@ static CompilerType GetSwiftTypeForVariableValueObject(
449449
SwiftLanguageRuntime *runtime) {
450450
// Check that the passed ValueObject is valid.
451451
if (!valobj_sp || valobj_sp->GetError().Fail())
452-
return CompilerType();
452+
return {};
453453
CompilerType result = valobj_sp->GetCompilerType();
454-
if (!result.IsValid())
455-
return CompilerType();
454+
if (!result)
455+
return {};
456456
result = runtime->BindGenericTypeParameters(*stack_frame_sp, result);
457+
if (!result)
458+
return {};
457459
if (!result.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
458-
return CompilerType();
460+
return {};
459461
return result;
460462
}
461463

@@ -1477,11 +1479,7 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
14771479
retry = true;
14781480
},
14791481
[&](const SwiftASTContextError &SACE) {
1480-
if (swift_ast_ctx->GetClangImporter())
1481-
DiagnoseSwiftASTContextError();
1482-
else
1483-
// Discard the shared scratch context and retry.
1484-
retry = true;
1482+
DiagnoseSwiftASTContextError();
14851483
},
14861484
[&](const StringError &SE) {
14871485
diagnostic_manager.PutString(eDiagnosticSeverityError,

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,14 +2197,15 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
21972197
// system. These modules must be imported from the
21982198
// SDK instead.
21992199
if (!StringRef(parent_path).startswith("/System/Library") &&
2200-
!IsDeviceSupport(parent_path.c_str()))
2200+
!IsDeviceSupport(parent_path.c_str())) {
22012201
LOG_PRINTF(LIBLLDB_LOG_TYPES,
22022202
"process_one_module(\"%s\") adding framework path "
22032203
"\"%s\".",
22042204
module_file.GetFilename().AsCString(""),
22052205
framework_path.c_str());
22062206
framework_search_paths.push_back(
22072207
{std::move(parent_path), /*system*/ false});
2208+
}
22082209
}
22092210
}
22102211
}
@@ -2868,52 +2869,51 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
28682869
const DiagnosticSeverity severity = SeverityForKind(diagnostic.kind);
28692870
const DiagnosticOrigin origin = eDiagnosticOriginSwift;
28702871

2871-
if (first_line > 0 && bufferID != UINT32_MAX &&
2872-
diagnostic.bufferID == bufferID && !diagnostic.bufferName.empty()) {
2873-
// Make sure the error line is in range.
2874-
if (diagnostic.line >= first_line && diagnostic.line <= last_line) {
2875-
// Need to remap the error/warning to a different line.
2876-
StreamString match;
2877-
match.Printf("%s:%u:", diagnostic.bufferName.str().c_str(),
2878-
diagnostic.line);
2879-
const size_t match_len = match.GetString().size();
2880-
size_t match_pos =
2881-
diagnostic.description.find(match.GetString().str());
2882-
if (match_pos != std::string::npos) {
2883-
// We have some <file>:<line>:" instances that need to be updated.
2884-
StreamString fixed_description;
2885-
size_t start_pos = 0;
2886-
do {
2887-
if (match_pos > start_pos)
2888-
fixed_description.Printf(
2889-
"%s", diagnostic.description.substr(start_pos, match_pos)
2890-
.c_str());
2891-
fixed_description.Printf(
2892-
"%s:%u:", diagnostic.bufferName.str().c_str(),
2893-
diagnostic.line - first_line + 1);
2894-
start_pos = match_pos + match_len;
2895-
match_pos = diagnostic.description.find(match.GetString().str(),
2896-
start_pos);
2897-
} while (match_pos != std::string::npos);
2898-
2899-
// Append any last remaining text.
2900-
if (start_pos < diagnostic.description.size())
2872+
if (first_line > 0 && bufferID != UINT32_MAX) {
2873+
// Make sure the error line is in range or in another file.
2874+
if (diagnostic.bufferID == bufferID && !diagnostic.bufferName.empty() &&
2875+
(diagnostic.line < first_line || diagnostic.line > last_line))
2876+
continue;
2877+
// Need to remap the error/warning to a different line.
2878+
StreamString match;
2879+
match.Printf("%s:%u:", diagnostic.bufferName.str().c_str(),
2880+
diagnostic.line);
2881+
const size_t match_len = match.GetString().size();
2882+
size_t match_pos = diagnostic.description.find(match.GetString().str());
2883+
if (match_pos != std::string::npos) {
2884+
// We have some <file>:<line>:" instances that need to be updated.
2885+
StreamString fixed_description;
2886+
size_t start_pos = 0;
2887+
do {
2888+
if (match_pos > start_pos)
29012889
fixed_description.Printf(
2902-
"%s", diagnostic.description
2903-
.substr(start_pos,
2904-
diagnostic.description.size() - start_pos)
2905-
.c_str());
2906-
2907-
auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2908-
fixed_description.GetData(), severity, origin, bufferID);
2909-
for (auto fixit : diagnostic.fixits)
2910-
new_diagnostic->AddFixIt(fixit);
2911-
2912-
diagnostic_manager.AddDiagnostic(std::move(new_diagnostic));
2890+
"%s",
2891+
diagnostic.description.substr(start_pos, match_pos).c_str());
2892+
fixed_description.Printf(
2893+
"%s:%u:", diagnostic.bufferName.str().c_str(),
2894+
diagnostic.line - first_line + 1);
2895+
start_pos = match_pos + match_len;
2896+
match_pos =
2897+
diagnostic.description.find(match.GetString().str(), start_pos);
2898+
} while (match_pos != std::string::npos);
2899+
2900+
// Append any last remaining text.
2901+
if (start_pos < diagnostic.description.size())
2902+
fixed_description.Printf(
2903+
"%s", diagnostic.description
2904+
.substr(start_pos,
2905+
diagnostic.description.size() - start_pos)
2906+
.c_str());
2907+
2908+
auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2909+
fixed_description.GetData(), severity, origin, bufferID);
2910+
for (auto fixit : diagnostic.fixits)
2911+
new_diagnostic->AddFixIt(fixit);
2912+
2913+
diagnostic_manager.AddDiagnostic(std::move(new_diagnostic));
2914+
if (diagnostic.kind == swift::DiagnosticKind::Error)
29132915
added_one_diagnostic = true;
29142916

2915-
continue;
2916-
}
29172917
}
29182918
}
29192919
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2823,8 +2823,34 @@ TypeSystemSwiftTypeRef::GetReferentType(opaque_compiler_type_t type) {
28232823

28242824
CompilerType
28252825
TypeSystemSwiftTypeRef::GetInstanceType(opaque_compiler_type_t type) {
2826-
return m_swift_ast_context->GetInstanceType(ReconstructType(type));
2826+
auto impl = [&]() -> CompilerType {
2827+
using namespace swift::Demangle;
2828+
Demangler dem;
2829+
NodePointer node = DemangleCanonicalType(dem, type);
2830+
2831+
if (!node)
2832+
return {};
2833+
if (ContainsUnresolvedTypeAlias(node)) {
2834+
// If we couldn't resolve all type aliases, we might be in a REPL session
2835+
// where getting to the debug information necessary for resolving that
2836+
// type alias isn't possible, or the user might have defined the
2837+
// type alias in the REPL. In these cases, fallback to asking the AST
2838+
// for the canonical type.
2839+
return m_swift_ast_context->GetInstanceType(ReconstructType(type));
2840+
}
2841+
2842+
if (node->getKind() == Node::Kind::Metatype) {
2843+
for (NodePointer child : *node)
2844+
if (child->getKind() == Node::Kind::Type)
2845+
return RemangleAsType(dem, child);
2846+
return {};
2847+
}
2848+
return {this, type};
2849+
};
2850+
VALIDATE_AND_RETURN(impl, GetInstanceType, type, (ReconstructType(type)),
2851+
(ReconstructType(type)));
28272852
}
2853+
28282854
TypeSystemSwift::TypeAllocationStrategy
28292855
TypeSystemSwiftTypeRef::GetAllocationStrategy(opaque_compiler_type_t type) {
28302856
return m_swift_ast_context->GetAllocationStrategy(ReconstructType(type));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)
3+
4+
include Makefile.rules
5+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
7+
class TestSwiftExprImport(TestBase):
8+
9+
mydir = TestBase.compute_mydir(__file__)
10+
11+
def setUp(self):
12+
TestBase.setUp(self)
13+
14+
# Don't run ClangImporter tests if Clangimporter is disabled.
15+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
16+
@swiftTest
17+
def test(self):
18+
"""Test error handling if the expression evaluator
19+
encounters a Clang import failure.
20+
"""
21+
self.build()
22+
23+
lldbutil.run_to_source_breakpoint(self, "break here",
24+
lldb.SBFileSpec('main.swift'))
25+
self.expect("expr -- import A", error=True,
26+
substrs=['SYNTAX_ERROR',
27+
'could', 'not', 'build', 'module'])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int i = SYNTAX_ERROR;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func f() {}
2+
3+
print("break here")
4+
f()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A {
2+
header "a.h"
3+
}

lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,33 @@ TEST_F(TestTypeSystemSwiftTypeRef, GetNumTemplateArguments) {
638638
CompilerType t = GetCompilerType(b.Mangle(n));
639639
ASSERT_EQ(t.GetNumTemplateArguments(), 1);
640640
}
641-
}
641+
}
642+
643+
TEST_F(TestTypeSystemSwiftTypeRef, GetInstanceType) {
644+
using namespace swift::Demangle;
645+
Demangler dem;
646+
NodeBuilder b(dem);
647+
{
648+
NodePointer n = b.GlobalType(
649+
b.Node(Node::Kind::Metatype,
650+
b.Node(Node::Kind::MetatypeRepresentation, "@thin"),
651+
b.Node(Node::Kind::Type,
652+
b.Node(Node::Kind::Structure,
653+
b.Node(Node::Kind::Module, "Swift"),
654+
b.Node(Node::Kind::Identifier, "String")))));
655+
656+
CompilerType t = GetCompilerType(b.Mangle(n));
657+
CompilerType instance_type = m_swift_ts.GetInstanceType(t.GetOpaqueQualType());
658+
ASSERT_EQ(instance_type.GetMangledTypeName(), "$sSSD");
659+
};
660+
{
661+
NodePointer n = b.GlobalType(
662+
b.Node(Node::Kind::Structure,
663+
b.Node(Node::Kind::Module, "Swift"),
664+
b.Node(Node::Kind::Identifier, "String")));
665+
666+
CompilerType t = GetCompilerType(b.Mangle(n));
667+
CompilerType instance_type = m_swift_ts.GetInstanceType(t.GetOpaqueQualType());
668+
ASSERT_EQ(instance_type.GetMangledTypeName(), "$sSSD");
669+
};
670+
};

0 commit comments

Comments
 (0)