Skip to content

Commit 3d2916f

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e7c8cd86dfd2' from swift/release/5.9 into stable/20221013
2 parents 5f533e7 + e7c8cd8 commit 3d2916f

File tree

2 files changed

+79
-24
lines changed

2 files changed

+79
-24
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
1919
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
20+
#include "Plugins/TypeSystem/Swift/SwiftDemangle.h"
2021
#include "lldb/Symbol/Function.h"
2122
#include "lldb/Symbol/Variable.h"
2223
#include "lldb/Symbol/VariableList.h"
@@ -3123,31 +3124,30 @@ TypeAndOrName SwiftLanguageRuntimeImpl::FixUpDynamicType(
31233124

31243125
bool SwiftLanguageRuntimeImpl::IsTaggedPointer(lldb::addr_t addr,
31253126
CompilerType type) {
3126-
swift::CanType swift_can_type = GetCanonicalSwiftType(type);
3127-
if (!swift_can_type)
3127+
Demangler dem;
3128+
auto *root = dem.demangleSymbol(type.GetMangledTypeName().GetStringRef());
3129+
using Kind = Node::Kind;
3130+
auto *unowned_node = swift_demangle::nodeAtPath(
3131+
root, {Kind::TypeMangling, Kind::Type, Kind::Unowned});
3132+
if (!unowned_node)
31283133
return false;
3129-
switch (swift_can_type->getKind()) {
3130-
case swift::TypeKind::UnownedStorage: {
3131-
Target &target = m_process.GetTarget();
3132-
llvm::Triple triple = target.GetArchitecture().GetTriple();
3133-
// On Darwin the Swift runtime stores unowned references to
3134-
// Objective-C objects as a pointer to a struct that has the
3135-
// actual object pointer at offset zero. The least significant bit
3136-
// of the reference pointer indicates whether the reference refers
3137-
// to an Objective-C or Swift object.
3138-
//
3139-
// This is a property of the Swift runtime(!). In the future it
3140-
// may be necessary to check for the version of the Swift runtime
3141-
// (or indirectly by looking at the version of the remote
3142-
// operating system) to determine how to interpret references.
3143-
if (triple.isOSDarwin())
3144-
// Check whether this is a reference to an Objective-C object.
3145-
if ((addr & 1) == 1)
3146-
return true;
3147-
} break;
3148-
default:
3149-
break;
3150-
}
3134+
3135+
Target &target = m_process.GetTarget();
3136+
llvm::Triple triple = target.GetArchitecture().GetTriple();
3137+
// On Darwin the Swift runtime stores unowned references to
3138+
// Objective-C objects as a pointer to a struct that has the
3139+
// actual object pointer at offset zero. The least significant bit
3140+
// of the reference pointer indicates whether the reference refers
3141+
// to an Objective-C or Swift object.
3142+
//
3143+
// This is a property of the Swift runtime(!). In the future it
3144+
// may be necessary to check for the version of the Swift runtime
3145+
// (or indirectly by looking at the version of the remote
3146+
// operating system) to determine how to interpret references.
3147+
if (triple.isOSDarwin())
3148+
// Check whether this is a reference to an Objective-C object.
3149+
if ((addr & 1) == 1)
3150+
return true;
31513151
return false;
31523152
}
31533153

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===-- SwiftDemangle.h ---------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef liblldb_SwiftDemangle_h_
14+
#define liblldb_SwiftDemangle_h_
15+
16+
#include "swift/Demangling/Demangle.h"
17+
#include "llvm/ADT/ArrayRef.h"
18+
19+
namespace lldb_private {
20+
namespace swift_demangle {
21+
22+
/// Access an inner node by following the given Node::Kind path.
23+
///
24+
/// Note: The Node::Kind path is relative to the given root node. The root
25+
/// node's Node::Kind must not be included in the path.
26+
inline swift::Demangle::NodePointer
27+
nodeAtPath(swift::Demangle::NodePointer root,
28+
llvm::ArrayRef<swift::Demangle::Node::Kind> kind_path) {
29+
if (!root)
30+
return nullptr;
31+
32+
auto *node = root;
33+
for (auto kind : kind_path) {
34+
bool found = false;
35+
for (auto *child : *node) {
36+
assert(child && "swift::Demangle::Node has null child");
37+
if (child && child->getKind() == kind) {
38+
node = child;
39+
found = true;
40+
break;
41+
}
42+
}
43+
// The current step (`kind`) of the path was not found in the children of
44+
// the current `node`. The requested path does not exist.
45+
if (!found)
46+
return nullptr;
47+
}
48+
49+
return node;
50+
}
51+
52+
} // namespace swift_demangle
53+
} // namespace lldb_private
54+
55+
#endif

0 commit comments

Comments
 (0)