Skip to content

[cxx-interop] Mark types with a destructor a non-trivial. #32402

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
Jul 10, 2020
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
1 change: 1 addition & 0 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ namespace {

if (D->isCxxNotTriviallyCopyable()) {
properties.setAddressOnly();
properties.setNonTrivial();
}

auto subMap = structType->getContextSubstitutionMap(&TC.M, D);
Expand Down
4 changes: 2 additions & 2 deletions test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module AccessSpecifiers {
header "access-specifiers.h"
}

module LoadableTypes {
header "loadable-types.h"
module TypeClassification {
header "type-classification.h"
}

module MemberwiseInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct StructWithSubobjectMoveAssignment {
};

struct StructWithDestructor {
~StructWithDestructor(){}
~StructWithDestructor() {}
};

struct StructWithInheritedDestructor : StructWithDestructor {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This test checks that we classify C++ types as loadable and address-only
// correctly.

import LoadableTypes
import TypeClassification

// Tests for individual special members

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-sil %s | %FileCheck %s

import TypeClassification

// Make sure that "StructWithDestructor" is marked as non-trivial by checking for a
// "destroy_addr".
// CHECK-LABEL: @$s4main24testStructWithDestructoryyF
// CHECK: [[AS:%.*]] = alloc_stack $StructWithDestructor
// CHECK: destroy_addr [[AS]]
// CHECK-LABEL: end sil function '$s4main24testStructWithDestructoryyF'
public func testStructWithDestructor() {
let d = StructWithDestructor()
}

// Make sure that "HasMemberWithDestructor" is marked as non-trivial by checking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasMemberWithDestructor => StructWithSubobjectDestructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops forgot about this. #33150.

// for a "destroy_addr".
// CHECK-LABEL: @$s4main33testStructWithSubobjectDestructoryyF
// CHECK: [[AS:%.*]] = alloc_stack $StructWithSubobjectDestructor
// CHECK: destroy_addr [[AS]]
// CHECK-LABEL: end sil function '$s4main33testStructWithSubobjectDestructoryyF'
public func testStructWithSubobjectDestructor() {
let d = StructWithSubobjectDestructor()
}