File: private-stored-member-type-layout.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (52 lines) | stat: -rw-r--r-- 3,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// RUN: %empty-directory(%t)

// Check that importing this module creates the right types

// RUN: %target-swift-frontend -emit-module-interface-path %t/private-stored-members.swiftinterface -module-name PrivateStoredMembers -emit-module -o %t/PrivateStoredMembers.swiftmodule %S/private-stored-members.swift
// RUN: %target-swift-frontend -emit-ir %s -I %t 2>&1 -DSHOULD_IMPORT | %FileCheck %s --check-prefix CHECK-EXEC --check-prefix CHECK

// Check that the types are also correct when importing a module created from an interface

// RUN: %target-swift-frontend -emit-module -o %t/PrivateStoredMembers.swiftmodule -module-name PrivateStoredMembers %t/private-stored-members.swiftinterface -disable-objc-attr-requires-foundation-module
// RUN: %target-swift-frontend -emit-ir %s -I %t 2>&1 -DSHOULD_IMPORT | %FileCheck %s --check-prefix CHECK-EXEC --check-prefix CHECK

// Check the types generated when the source file is the primary file, and ensure they're the same layout.

// RUN: %target-swift-frontend -emit-ir %S/private-stored-members.swift %s 2>&1 -module-name main | %FileCheck %s --check-prefix CHECK-MAIN --check-prefix CHECK-EXEC

// These two appear out-of-order between run lines

// CHECK-DAG: [[MYSTRUCT:%T20PrivateStoredMembers8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>

// CHECK-MAIN-DAG: [[MYCLASS:%T4main7MyClassC]] = type <{ %swift.refcounted, %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
// CHECK-MAIN-DAG: [[MYSTRUCT:%T4main8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>

#if SHOULD_IMPORT
import PrivateStoredMembers
#endif

// CHECK-EXEC: swiftcc void @"$s{{[^ ]+}}8makeUseryyF"() #0 {
public func makeUser() {
  let ptr = UnsafeMutablePointer<MyStruct>.allocate(capacity: 1)
  // CHECK-EXEC: %.publicEndVar = getelementptr inbounds [[MYSTRUCT]], ptr %{{[0-9]+}}, i32 0, i32 [[PUBLIC_END_VAR_IDX:12]]
  // CHECK-EXEC: %.publicEndVar._value = getelementptr inbounds %Ts5Int64V, ptr %.publicEndVar, i32 0, i32 0
  // CHECK-EXEC: store i64 4, ptr %.publicEndVar._value
  ptr.pointee.publicEndVar = 4

  // CHECK-EXEC: %.publicEndVar1 = getelementptr inbounds [[MYSTRUCT]], ptr %{{[0-9]+}}, i32 0, i32 [[PUBLIC_END_VAR_IDX]]
  // CHECK-EXEC: %.publicEndVar1._value = getelementptr inbounds %Ts5Int64V, ptr %.publicEndVar1, i32 0, i32 0
  // CHECK-EXEC: [[PUBLIC_END_VAR_LOAD:%[0-9]+]] = load i64, ptr %.publicEndVar1._value, align 8

  // CHECK-EXEC: %.publicVar = getelementptr inbounds [[MYSTRUCT]], ptr %{{[0-9]+}}, i32 0, i32 0
  // CHECK-EXEC: %.publicVar._value = getelementptr inbounds %Ts5Int64V, ptr %.publicVar, i32 0, i32 0
  // CHECK-EXEC: store i64 [[PUBLIC_END_VAR_LOAD]], ptr %.publicVar._value, align 8
  ptr.pointee.publicVar = ptr.pointee.publicEndVar
  ptr.deallocate()

  // CHECK-EXEC: %[[MYCLASS_INIT:[0-9]+]] = call swiftcc ptr @"$s{{[^ ]+}}7MyClassCACycfC"(ptr swiftself %{{[0-9]+}})
  let myClass = MyClass()

  // These are uninteresting as they just call into the standard getter and setter.
  myClass.publicEndVar = 4
  myClass.publicVar = myClass.publicEndVar
}