Skip to content

Commit 04a0a33

Browse files
Merge pull request #8072 from adrian-prantl/121225616
Fix extra inhabitants count for Clang-imported pointers.
2 parents 1910560 + 0b311c3 commit 04a0a33

File tree

8 files changed

+77
-11
lines changed

8 files changed

+77
-11
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ SwiftLanguageRuntimeImpl::emplaceClangTypeInfo(
397397
// The stride is the size rounded up to alignment.
398398
const size_t byte_stride = llvm::alignTo(*byte_size, byte_align);
399399
unsigned extra_inhabitants = 0;
400-
if (clang_type.IsPointerType() &&
401-
TypeSystemSwiftTypeRef::IsKnownSpecialImportedType(
402-
clang_type.GetDisplayTypeName().GetStringRef()))
400+
if (clang_type.IsPointerType())
403401
extra_inhabitants = swift::swift_getHeapObjectExtraInhabitantCount();
404402

405403
if (fields.empty()) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ TypeSystemSwiftTypeRef::GetBaseName(swift::Demangle::NodePointer node) {
177177
}
178178
}
179179

180-
bool TypeSystemSwiftTypeRef::IsKnownSpecialImportedType(llvm::StringRef name) {
181-
return name == "NSNotificationName" ||
182-
swift::ClangImporter::isKnownCFTypeName(name);
183-
}
184-
185180
/// Create a mangled name for a type node.
186181
static swift::Demangle::ManglingErrorOr<std::string>
187182
GetMangledName(swift::Demangle::Demangler &dem,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
359359
/// Return the base name of the topmost nominal type.
360360
static llvm::StringRef GetBaseName(swift::Demangle::NodePointer node);
361361

362-
/// Return whether the type is known to be specially handled by the compiler.
363-
static bool IsKnownSpecialImportedType(llvm::StringRef name);
364-
365362
/// Use API notes to determine the swiftified name of \p clang_decl.
366363
std::string GetSwiftName(const clang::Decl *clang_decl,
367364
TypeSystemClang &clang_typesystem) override;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef struct {} *StructPtr;
2+
// Simulates the CoreFoundation CF_BRIDGED_TYPE(id) macro.
3+
typedef struct __attribute__((objc_bridge(id))) {} *BridgedPtr;
4+
typedef id OpaqueObj;
5+
typedef void *VoidPtr;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Foo {
2+
header "Foo.h"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_OBJC_INTEROP := 1
2+
SWIFT_SOURCES := main.swift
3+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)/Foo
4+
include Makefile.rules
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 TestSwiftClangImporterExtraInhabitants(TestBase):
8+
@swiftTest
9+
@skipUnlessDarwin
10+
# Don't run ClangImporter tests if Clangimporter is disabled.
11+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
12+
def test(self):
13+
"""Test that the extra inhabitants are correctly computed for various
14+
kinds of Objective-C pointers, by using them in enums."""
15+
self.build()
16+
lldbutil.run_to_source_breakpoint(self, 'break here',
17+
lldb.SBFileSpec('main.swift'))
18+
var = self.frame().FindVariable("mystruct")
19+
check = lldbutil.check_variable
20+
21+
check(self, var.GetChildAtIndex(0), value="0")
22+
check(self, var.GetChildAtIndex(1),
23+
typename="Swift.Optional<Swift.OpaquePointer>",
24+
summary="nil")
25+
26+
check(self, var.GetChildAtIndex(2), value="2")
27+
check(self, var.GetChildAtIndex(3),
28+
typename="Swift.Optional<Foo.BridgedPtr>",
29+
summary="nil")
30+
31+
check(self, var.GetChildAtIndex(4), value="4")
32+
check(self, var.GetChildAtIndex(5),
33+
typename="Swift.Optional<Swift.AnyObject>",
34+
summary="nil")
35+
36+
check(self, var.GetChildAtIndex(6), value="6")
37+
check(self, var.GetChildAtIndex(7),
38+
typename="Swift.Optional<Swift.UnsafeMutableRawPointer>",
39+
summary="nil")
40+
41+
check(self, var.GetChildAtIndex(8), value="8")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Foo
2+
3+
class MyStruct {
4+
let m0 : Int = 0
5+
let pointer : StructPtr? = nil
6+
let m2 : Int = 2
7+
let bridged : BridgedPtr? = nil
8+
let m4 : Int = 4
9+
let opaque : OpaqueObj? = nil
10+
let m6 : Int = 6
11+
let void : VoidPtr? = nil
12+
let m8 : Int = 8
13+
init() {}
14+
}
15+
16+
func use<T>(_ t: T) {}
17+
18+
func main() {
19+
let mystruct = MyStruct()
20+
use(mystruct) // break here
21+
}
22+
23+
main()

0 commit comments

Comments
 (0)