-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] [IRGen] TypeInfo for address-only types. #32973
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
zoecarver
merged 1 commit into
swiftlang:master
from
zoecarver:cxx/address-only-type-info
Aug 10, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
test/Interop/Cxx/class/type-classification-non-trivial-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir | %FileCheck %s | ||
|
||
// Verify that non-trival/address-only C++ classes are constructed and accessed | ||
// correctly. Make sure that we correctly IRGen functions that construct | ||
// non-trivial C++ classes, take those classes as a parameter, and access those | ||
// classes members. | ||
|
||
import TypeClassification | ||
|
||
// TODO: C++ objects with destructors should be tested here once we fully | ||
// support them. | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main37testStructWithCopyConstructorAndValueSbyF" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add an explanation of what these tests are verifying, so that future when IRGen patterns change people can update the CHECK lines appropriately, and not accidentally eliminate the part that we're thinking we are testing here. |
||
// CHECK: [[OBJ:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[VAL_ELEMENT:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[OBJ]], i32 0, i32 0 | ||
// CHECK: [[VAL_INT:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[VAL_ELEMENT]], i32 0, i32 0 | ||
// CHECK: store i32 42, i32* [[VAL_INT]] | ||
// CHECK: ret i1 true | ||
public func testStructWithCopyConstructorAndValue() -> Bool { | ||
let obj = StructWithCopyConstructorAndValue(value: 42) | ||
return obj.value == 42 | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main46testStructWithSubobjectCopyConstructorAndValueSbyF"() | ||
// CHECK: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[OBJ:%.*]] = alloca %TSo42StructWithSubobjectCopyConstructorAndValueV | ||
// CHECK: alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[MEMBER_ELEMENT:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]], i32 0, i32 0 | ||
// CHECK: [[MEMBER_VALUE:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[MEMBER_ELEMENT]], i32 0, i32 0 | ||
// CHECK: store i32 42, i32* [[MEMBER_VALUE]] | ||
// CHECK: %obj.member = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* [[OBJ]], i32 0, i32 0 | ||
// CHECK: [[TEMP_MEMBER:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[TMP]], i32 0, i32 0 | ||
// CHECK: [[TEMP_MEMBER_VALUE:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[TEMP_MEMBER]], i32 0, i32 0 | ||
// CHECK: [[LHS:%.*]] = load i32, i32* [[TEMP_MEMBER_VALUE]] | ||
// CHECK: [[OUT:%.*]] = icmp eq i32 [[LHS]], 42 | ||
// CHECK: ret i1 [[OUT]] | ||
public func testStructWithSubobjectCopyConstructorAndValue() -> Bool { | ||
let member = StructWithCopyConstructorAndValue(value: 42) | ||
let obj = StructWithSubobjectCopyConstructorAndValue(member: member) | ||
return obj.member.value == 42 | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main041testStructWithCopyConstructorAndSubobjectefG5ValueSbyF"() | ||
// CHECK: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: alloca %TSo037StructWithCopyConstructorAndSubobjectcdE5ValueV | ||
// CHECK: alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[TEMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[MEMBER_VAL:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]], i32 0, i32 0 | ||
// CHECK: [[MEMBER_VAL_VAL:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[MEMBER_VAL]], i32 0, i32 0 | ||
// CHECK: store i32 42, i32* [[MEMBER_VAL_VAL]] | ||
// CHECK: [[TEMP_MEMBER:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[TEMP]], i32 0, i32 0 | ||
// CHECK: [[TEMP_MEMBER_VAL:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[TEMP_MEMBER]], i32 0, i32 0 | ||
// CHECK: [[LHS:%.*]] = load i32, i32* [[TEMP_MEMBER_VAL]] | ||
// CHECK: [[OUT:%.*]] = icmp eq i32 [[LHS]], 42 | ||
// CHECK: ret i1 [[OUT]] | ||
public func testStructWithCopyConstructorAndSubobjectCopyConstructorAndValue() | ||
-> Bool { | ||
let member = StructWithCopyConstructorAndValue(value: 42) | ||
let obj = StructWithCopyConstructorAndSubobjectCopyConstructorAndValue( | ||
member: member | ||
) | ||
return obj.member.value == 42 | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main4test3objSbSo33StructWithCopyConstructorAndValueV_tF"(%TSo33StructWithCopyConstructorAndValueV* noalias nocapture dereferenceable(4) %0) | ||
// CHECK: [[VAL:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* %0, i32 0, i32 0 | ||
// CHECK: [[VAL_VAL:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[VAL]], i32 0, i32 0 | ||
// CHECK: [[LHS:%.*]] = load i32, i32* [[VAL_VAL]] | ||
// CHECK: [[OUT:%.*]] = icmp eq i32 %1, 42 | ||
// CHECK: ret i1 [[OUT]] | ||
public func test(obj: StructWithCopyConstructorAndValue) -> Bool { | ||
return obj.value == 42 | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main4test3objSbSo42StructWithSubobjectCopyConstructorAndValueV_tF"(%TSo42StructWithSubobjectCopyConstructorAndValueV* noalias nocapture dereferenceable(4) %0) | ||
// CHECK: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK: [[MEMBER:%.*]] = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* %0, i32 0, i32 0 | ||
// CHECK: [[VAL:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[TMP]], i32 0, i32 0 | ||
// CHECK: [[VAL_VAL:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[VAL]], i32 0, i32 0 | ||
// CHECK: [[LHS:%.*]] = load i32, i32* [[VAL_VAL]] | ||
// CHECK: [[OUT:%.*]] = icmp eq i32 [[LHS]], 42 | ||
// CHECK: ret i1 [[OUT]] | ||
public func test(obj: StructWithSubobjectCopyConstructorAndValue) -> Bool { | ||
return obj.member.value == 42 | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}i1 @"$s4main4test3objSbSo037StructWithCopyConstructorAndSubobjectfgH5ValueV_tF"(%TSo037StructWithCopyConstructorAndSubobjectcdE5ValueV* noalias nocapture dereferenceable(4) %0) | ||
// CHECK:[[TEMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV | ||
// CHECK:[[VAL:%.*]] = getelementptr inbounds %TSo33StructWithCopyConstructorAndValueV, %TSo33StructWithCopyConstructorAndValueV* [[TEMP]], i32 0, i32 0 | ||
// CHECK:[[VAL_VAL:%.*]] = getelementptr inbounds %Ts5Int32V, %Ts5Int32V* [[VAL]], i32 0, i32 0 | ||
// CHECK:[[LHS:%.*]] = load i32, i32* [[VAL_VAL]] | ||
// CHECK:[[OUT:%.*]] = icmp eq i32 [[LHS]], 42 | ||
// CHECK:ret i1 [[OUT]] | ||
public func test( | ||
obj: StructWithCopyConstructorAndSubobjectCopyConstructorAndValue | ||
) -> Bool { | ||
return obj.member.value == 42 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate (but also unrelated to this change). I was meaning to submit a fix for this and forgot. Maybe I'll have time this weekend. Otherwise, I'll do it next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #32591.