-
Notifications
You must be signed in to change notification settings - Fork 10.5k
IRGen: Work around RemoteMirror bug generating reflection info for empty builtin types. #29037
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
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
75 changes: 75 additions & 0 deletions
75
validation-test/Reflection/reflect_empty_struct_compat.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,75 @@ | ||
// RUN: %empty-directory(%t) | ||
|
||
// RUN: %target-build-swift -lswiftSwiftReflectionTest -I %S/Inputs/EmptyStruct/ %s -o %t/reflect_empty_struct -target x86_64-apple-macosx10.15.0 | ||
// RUN: %target-codesign %t/reflect_empty_struct | ||
// RUN: %target-run %target-swift-reflection-test %t/reflect_empty_struct | %FileCheck %s --check-prefix=CHECK-%target-ptrsize --dump-input fail | ||
|
||
// RUN: %target-build-swift -lswiftSwiftReflectionTest -I %S/Inputs/EmptyStruct/ %s -o %t/reflect_empty_struct -target x86_64-apple-macosx10.14.0 | ||
// RUN: %target-codesign %t/reflect_empty_struct | ||
// RUN: %target-run %target-swift-reflection-test %t/reflect_empty_struct | %FileCheck %s --check-prefix=CHECK-%target-ptrsize --dump-input fail | ||
|
||
// REQUIRES: objc_interop | ||
// REQUIRES: executable_test | ||
// REQUIRES: OS=macosx | ||
|
||
import SwiftReflectionTest | ||
|
||
import EmptyStruct | ||
|
||
@_alignment(1) struct EmptyStruct { } | ||
class Class { | ||
var a = EmptyStruct() | ||
var b: Any = EmptyStruct() | ||
var c = EmptyStructC() | ||
var d: Any = EmptyStructC() | ||
} | ||
|
||
var obj = Class() | ||
|
||
reflect(object: obj) | ||
|
||
// CHECK-64: Reflecting an object. | ||
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}} | ||
// CHECK-64: Type reference: | ||
// CHECK-64: (class reflect_empty_struct.Class) | ||
|
||
// CHECK-64: Type info: | ||
// CHECK-64: (class_instance size=80 alignment=8 stride=80 num_extra_inhabitants=0 bitwise_takable=1 | ||
// CHECK-64: (field name=a offset=16 | ||
// CHECK-64: (struct size=0 alignment=1 stride=1 num_extra_inhabitants=0 bitwise_takable=1)) | ||
// CHECK-64: (field name=b offset=16 | ||
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1 | ||
// CHECK-64: (field name=metadata offset=24 | ||
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1)))) | ||
// CHECK-64: (field name=c offset=48 | ||
// CHECK-64: (struct size=0 alignment=1 stride=1 num_extra_inhabitants=0 bitwise_takable=1)) | ||
// CHECK-64: (field name=d offset=48 | ||
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1 | ||
// CHECK-64: (field name=metadata offset=24 | ||
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))) | ||
|
||
// CHECK-32: Reflecting an object. | ||
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}} | ||
// CHECK-32: Type reference: | ||
// CHECK-32: (class reflect_empty_struct.Class) | ||
|
||
// CHECK-32: Type info: | ||
// CHECK-32: (class_instance size=40 alignment=4 stride=40 num_extra_inhabitants=0 bitwise_takable=1 | ||
// CHECK-32: (field name=a offset=8 | ||
// CHECK-32: (struct size=0 alignment=1 stride=1 num_extra_inhabitants=0 bitwise_takable=1)) | ||
// CHECK-32: (field name=b offset=8 | ||
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1 | ||
// CHECK-32: (field name=metadata offset=12 | ||
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1)))) | ||
// CHECK-32: (field name=c offset=24 | ||
// CHECK-32: (struct size=0 alignment=1 stride=1 num_extra_inhabitants=0 bitwise_takable=1)) | ||
// CHECK-32: (field name=d offset=24 | ||
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1 | ||
// CHECK-32: (field name=metadata offset=12 | ||
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))) | ||
|
||
doneReflecting() | ||
|
||
// CHECK-64: Done. | ||
|
||
// CHECK-32: Done. |
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.
Why are you declaring the alignment here?
Uh oh!
There was an error while loading. Please reload this page.
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.
The compiler always generates
BuiltinTypeDescriptor
s for types with declared alignment (because the normal layout algorithm would mis-align them), so this is just to exercise that code path. An empty type should not be able to affect the layout of its enclosing aggregate regardless of its supposed alignment, so it should be OK to fall back to an empty struct layout.