-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Detect IndirectFields nested in non-importable anon-union. #37287
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@class C; | ||
@interface C | ||
{} | ||
@end | ||
|
||
struct S { | ||
union { | ||
C *t; | ||
char c; | ||
}; | ||
S(const S &s) {} | ||
~S() { } | ||
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. Additionally, it's odd that this doesn't fail when the special members are gone, this contributes to my thinking that we don't know the whole story here. 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. Ah yeah I agreed. I thought there was something going on where the special members of the containing struct affected the anon-union's. If it is ok with you to land this so I can be unblocked, I will continue investigating in the background if that is ok? |
||
int f() { return 42; } | ||
}; | ||
|
||
S *getSPtr(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module AnonymousUnionPartlyInvalid { | ||
header "anonymous-union-partly-invalid.h" | ||
requires cplusplus | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: %target-swift-ide-test -print-module -module-to-print=AnonymousUnionPartlyInvalid -I %S/Inputs -source-filename=x -enable-cxx-interop -enable-objc-interop | %FileCheck %s | ||
|
||
// CHECK: class C { | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: struct S { | ||
// CHECK-NEXT: mutating func f() -> Int32 | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: func getSPtr() -> UnsafeMutablePointer<S>! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: %swift -I %S/Inputs -enable-cxx-interop -enable-objc-interop -emit-ir %s | %FileCheck %s | ||
|
||
import AnonymousUnionPartlyInvalid | ||
|
||
let sPtr = getSPtr() | ||
let a = sPtr![0].f() | ||
|
||
// CHECK: i32 @main | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: bitcast | ||
// CHECK-NEXT: call %struct.S | ||
// CHECK-NEXT: ptrtoint %struct.S | ||
|
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.
From the other patch:
I'm a bit confused. Where is the destructor deleted?
If that's the problem I think we actually need to fix this differently: figure out why clang thinks the destructor is deleted here (or maybe I'm just missing something 😁). Then we should try to reproduce this assertion again using a "differently invalid" type.
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.
Actually I think it's because the destructor for an anonymous union here is not deleted (sorry read the condition inverted), and since I dont think theres no way to do a
~() = delete;
I can't try this out otherwise for an anonymous union. I think the reason for this is that in this similar instance:The anon union contains an arc managed pointer so the destructor can't be trivial but I am not certain of this.
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.
If the destructor is not deleted, then why can't we import it? I want to make sure we completely understand the problem here.
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.
Here's an idea about why this might be failing, it comes from the observation that a similar C++ program doesn't fail:
In the above program,
C
isn't able to be imported, but its pointer type is still imported asOpaquePointer
so we get:However, as I understand it (and this might not be correct), this is not the case for ObjC types: if they can't be imported, their type is nullptr. This might be the reason it's only happening for ObjC.
However, I'm still not sure we know the answer to the question: why is
isCxxRecordImportable
returningfalse
?