Skip to content

Fix extra inhabitants count for Clang-imported pointers. #8072

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 1 commit into from
Jan 29, 2024
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 @@ -397,9 +397,7 @@ SwiftLanguageRuntimeImpl::emplaceClangTypeInfo(
// The stride is the size rounded up to alignment.
const size_t byte_stride = llvm::alignTo(*byte_size, byte_align);
unsigned extra_inhabitants = 0;
if (clang_type.IsPointerType() &&
TypeSystemSwiftTypeRef::IsKnownSpecialImportedType(
clang_type.GetDisplayTypeName().GetStringRef()))
if (clang_type.IsPointerType())
extra_inhabitants = swift::swift_getHeapObjectExtraInhabitantCount();

if (fields.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ TypeSystemSwiftTypeRef::GetBaseName(swift::Demangle::NodePointer node) {
}
}

bool TypeSystemSwiftTypeRef::IsKnownSpecialImportedType(llvm::StringRef name) {
return name == "NSNotificationName" ||
swift::ClangImporter::isKnownCFTypeName(name);
}

/// Create a mangled name for a type node.
static swift::Demangle::ManglingErrorOr<std::string>
GetMangledName(swift::Demangle::Demangler &dem,
Expand Down
3 changes: 0 additions & 3 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
/// Return the base name of the topmost nominal type.
static llvm::StringRef GetBaseName(swift::Demangle::NodePointer node);

/// Return whether the type is known to be specially handled by the compiler.
static bool IsKnownSpecialImportedType(llvm::StringRef name);

/// Use API notes to determine the swiftified name of \p clang_decl.
std::string GetSwiftName(const clang::Decl *clang_decl,
TypeSystemClang &clang_typesystem) override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typedef struct {} *StructPtr;
// Simulates the CoreFoundation CF_BRIDGED_TYPE(id) macro.
typedef struct __attribute__((objc_bridge(id))) {} *BridgedPtr;
typedef id OpaqueObj;
typedef void *VoidPtr;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo {
header "Foo.h"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_OBJC_INTEROP := 1
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)/Foo
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2

class TestSwiftClangImporterExtraInhabitants(TestBase):
@swiftTest
@skipUnlessDarwin
# Don't run ClangImporter tests if Clangimporter is disabled.
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
def test(self):
"""Test that the extra inhabitants are correctly computed for various
kinds of Objective-C pointers, by using them in enums."""
self.build()
lldbutil.run_to_source_breakpoint(self, 'break here',
lldb.SBFileSpec('main.swift'))
var = self.frame().FindVariable("mystruct")
check = lldbutil.check_variable

check(self, var.GetChildAtIndex(0), value="0")
check(self, var.GetChildAtIndex(1),
typename="Swift.Optional<Swift.OpaquePointer>",
summary="nil")

check(self, var.GetChildAtIndex(2), value="2")
check(self, var.GetChildAtIndex(3),
typename="Swift.Optional<Foo.BridgedPtr>",
summary="nil")

check(self, var.GetChildAtIndex(4), value="4")
check(self, var.GetChildAtIndex(5),
typename="Swift.Optional<Swift.AnyObject>",
summary="nil")

check(self, var.GetChildAtIndex(6), value="6")
check(self, var.GetChildAtIndex(7),
typename="Swift.Optional<Swift.UnsafeMutableRawPointer>",
summary="nil")

check(self, var.GetChildAtIndex(8), value="8")
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foo

class MyStruct {
let m0 : Int = 0
let pointer : StructPtr? = nil
let m2 : Int = 2
let bridged : BridgedPtr? = nil
let m4 : Int = 4
let opaque : OpaqueObj? = nil
let m6 : Int = 6
let void : VoidPtr? = nil
let m8 : Int = 8
init() {}
}

func use<T>(_ t: T) {}

func main() {
let mystruct = MyStruct()
use(mystruct) // break here
}

main()