Skip to content

Commit 5e2d66a

Browse files
authored
Merge pull request #16347 from compnerd/silgen
SILGen Tests
2 parents 630a697 + 8b21fde commit 5e2d66a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+148
-165
lines changed

test/IDE/Inputs/custom-modules/ImportAsMemberC.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ _Nonnull CCPowerSupplyRef CCPowerSupplyCreate(double watts)
1111
_Nonnull CCRefrigeratorRef CCRefrigeratorCreate(CCPowerSupplyRef _Nonnull power)
1212
__attribute__((swift_name("CCRefrigerator.init(powerSupply:)")));
1313

14-
void CCRefrigeratorOpen(CCRefrigeratorRef fridge)
14+
void CCRefrigeratorOpen(_Null_unspecified CCRefrigeratorRef fridge)
1515
__attribute__((swift_name("CCRefrigerator.open(self:)")));
1616

1717
_Nonnull CCMutableRefrigeratorRef CCRefrigeratorCreateMutable(_Nonnull CCPowerSupplyRef power)
1818
__attribute__((swift_name("CCMutableRefrigerator.init(powerSupply:)")));
1919

20-
_Nonnull CCPowerSupplyRef CCRefrigeratorGetPowerSupply(CCRefrigeratorRef fridge)
20+
_Nonnull CCPowerSupplyRef CCRefrigeratorGetPowerSupply(_Null_unspecified CCRefrigeratorRef fridge)
2121
__attribute__((swift_name("getter:CCRefrigerator.powerSupply(self:)")));
2222

23-
void CCRefrigeratorSetPowerSupply(CCRefrigeratorRef fridge,
23+
void CCRefrigeratorSetPowerSupply(_Null_unspecified CCRefrigeratorRef fridge,
2424
CCPowerSupplyRef _Nonnull powerSupply)
2525
__attribute__((swift_name("setter:CCRefrigerator.powerSupply(self:_:)")));
2626

27-
extern const CCPowerSupplyRef kCCPowerSupplySemiModular
27+
extern const _Null_unspecified CCPowerSupplyRef kCCPowerSupplySemiModular
2828
__attribute__((swift_name("CCPowerSupplyRef.semiModular")));
2929

3030
_Nonnull CCPowerSupplyRef CCPowerSupplyCreateDangerous(void)

test/IDE/Inputs/custom-modules/ImportAsMemberClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ __attribute__((swift_name("SomeClass.doIt(self:)")))
2323
void IAMSomeClassDoIt(IAMSomeClass * _Nonnull someClass);
2424

2525
@interface UnavailableDefaultInit : NSObject
26-
-(instancetype)init __attribute__((availability(swift,unavailable)));
26+
-(_Null_unspecified instancetype)init __attribute__((availability(swift,unavailable)));
2727
@end
2828

2929
@interface UnavailableDefaultInitSub : UnavailableDefaultInit

test/IDE/Inputs/custom-modules/Newtype.h

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,57 +40,57 @@ extern const int kRawInt;
4040
extern void takesMyInt(MyInt);
4141

4242
typedef NSString * NSURLResourceKey __attribute((swift_newtype(struct)));
43-
extern NSURLResourceKey const NSURLIsRegularFileKey;
44-
extern NSURLResourceKey const NSURLIsDirectoryKey;
45-
extern NSURLResourceKey const NSURLLocalizedNameKey;
43+
extern _Null_unspecified NSURLResourceKey const NSURLIsRegularFileKey;
44+
extern _Null_unspecified NSURLResourceKey const NSURLIsDirectoryKey;
45+
extern _Null_unspecified NSURLResourceKey const NSURLLocalizedNameKey;
4646

4747
// Special case: Notifications
48-
extern const NSString *FooNotification;
49-
extern const NSString *kBarNotification;
50-
extern const NSString *NSWibbleNotification;
48+
extern const NSString * _Null_unspecified FooNotification;
49+
extern const NSString * _Null_unspecified kBarNotification;
50+
extern const NSString * _Null_unspecified NSWibbleNotification;
5151

5252
// But not just 'Notification'
53-
extern const NSString *kNotification;
54-
extern const NSString *Notification;
53+
extern const NSString * _Null_unspecified kNotification;
54+
extern const NSString * _Null_unspecified Notification;
5555

5656
// Nor when explicitly swift_name-ed
57-
extern const NSString *kSNNotification
57+
extern const NSString * _Null_unspecified kSNNotification
5858
__attribute((swift_name("swiftNamedNotification")));
5959

6060
// Test CFStringRef
6161
typedef CFStringRef CFNewType __attribute((swift_newtype(struct)));
6262

6363
// CF audited
6464
_Pragma("clang arc_cf_code_audited begin")
65-
extern const CFNewType MyCFNewTypeValue;
66-
extern CFNewType FooAudited(void);
65+
extern _Null_unspecified const CFNewType MyCFNewTypeValue;
66+
extern _Null_unspecified CFNewType FooAudited(void);
6767
_Pragma("clang arc_cf_code_audited end")
68-
extern const CFNewType MyCFNewTypeValueUnauditedButConst;
68+
extern _Null_unspecified const CFNewType MyCFNewTypeValueUnauditedButConst;
6969

7070
// un-audited CFStringRef
71-
extern CFNewType MyCFNewTypeValueUnaudited;
72-
extern CFNewType FooUnaudited(void);
71+
extern _Null_unspecified CFNewType MyCFNewTypeValueUnaudited;
72+
extern _Null_unspecified CFNewType FooUnaudited(void);
7373

7474
// Tests to show identical calling convention / binary representation for
7575
// new_type and non-new_type
7676
typedef CFStringRef MyABINewType __attribute((swift_newtype(struct)));
7777
typedef CFStringRef MyABIOldType;
7878
_Pragma("clang arc_cf_code_audited begin")
79-
extern const MyABINewType kMyABINewTypeGlobal;
80-
extern const MyABIOldType kMyABIOldTypeGlobal;
81-
extern MyABINewType getMyABINewType(void);
82-
extern MyABIOldType getMyABIOldType(void);
83-
extern void takeMyABINewType(MyABINewType);
84-
extern void takeMyABIOldType(MyABIOldType);
79+
extern _Null_unspecified const MyABINewType kMyABINewTypeGlobal;
80+
extern _Null_unspecified const MyABIOldType kMyABIOldTypeGlobal;
81+
extern _Null_unspecified MyABINewType getMyABINewType(void);
82+
extern _Null_unspecified MyABIOldType getMyABIOldType(void);
83+
extern void takeMyABINewType(_Null_unspecified MyABINewType);
84+
extern void takeMyABIOldType(_Null_unspecified MyABIOldType);
8585

8686
extern void takeMyABINewTypeNonNull(_Nonnull MyABINewType);
8787
extern void takeMyABIOldTypeNonNull(_Nonnull MyABIOldType);
8888
_Pragma("clang arc_cf_code_audited end")
8989

9090
typedef NSString *MyABINewTypeNS __attribute((swift_newtype(struct)));
9191
typedef NSString *MyABIOldTypeNS;
92-
extern MyABINewTypeNS getMyABINewTypeNS(void);
93-
extern MyABIOldTypeNS getMyABIOldTypeNS(void);
92+
extern _Null_unspecified MyABINewTypeNS getMyABINewTypeNS(void);
93+
extern _Null_unspecified MyABIOldTypeNS getMyABIOldTypeNS(void);
9494
extern void takeMyABINewTypeNonNullNS(_Nonnull MyABINewTypeNS);
9595
extern void takeMyABIOldTypeNonNullNS(_Nonnull MyABIOldTypeNS);
9696

@@ -100,31 +100,34 @@ typedef struct {int i;} NSSomeContext;
100100
typedef NSString *NSSomeContextName __attribute((swift_newtype(struct)))
101101
__attribute((swift_name("NSSomeContext.Name")));
102102

103-
extern const NSSomeContextName NSMyContextName;
103+
extern _Null_unspecified const NSSomeContextName NSMyContextName;
104104

105105
typedef struct T *TRef __attribute((swift_newtype(struct)));
106106
typedef const struct T *ConstTRef __attribute((swift_newtype(struct)));
107107
extern _Nonnull TRef create_T(void);
108108
extern _Nonnull ConstTRef create_ConstT(void);
109-
extern void destroy_T(TRef);
110-
extern void destroy_ConstT(ConstTRef);
109+
extern void destroy_T(_Null_unspecified TRef);
110+
extern void destroy_ConstT(_Null_unspecified ConstTRef);
111111

112-
extern void mutate_TRef_Pointee(TRef) __attribute((swift_name("TRef.mutatePointee(self:)")));
113-
extern void mutate_TRef(TRef *) __attribute((swift_name("TRef.mutate(self:)")));
114-
extern void use_ConstT(ConstTRef)
112+
extern void mutate_TRef_Pointee(_Null_unspecified TRef) __attribute((swift_name("TRef.mutatePointee(self:)")));
113+
extern void mutate_TRef(_Null_unspecified TRef * _Null_unspecified) __attribute((swift_name("TRef.mutate(self:)")));
114+
extern void use_ConstT(_Null_unspecified ConstTRef)
115115
__attribute((swift_name("ConstTRef.use(self:)")));
116116

117117
typedef struct T *_Nonnull *TRefRef __attribute((swift_newtype(struct)));
118118
typedef struct T *_Nonnull const *ConstTRefRef
119119
__attribute((swift_newtype(struct)));
120120
extern _Nonnull TRefRef create_TRef(void);
121121
extern _Nonnull ConstTRefRef create_ConstTRef(void);
122-
extern void destroy_TRef(TRefRef);
123-
extern void destroy_ConstTRef(ConstTRefRef);
122+
extern void destroy_TRef(_Null_unspecified TRefRef);
123+
extern void destroy_ConstTRef(_Null_unspecified ConstTRefRef);
124124

125-
extern void mutate_TRefRef_Pointee(TRefRef)
125+
extern void mutate_TRefRef_Pointee(_Null_unspecified TRefRef)
126126
__attribute((swift_name("TRefRef.mutatePointee(self:)")));
127-
extern void mutate_TRefRef(TRefRef*)
127+
extern void mutate_TRefRef(_Null_unspecified TRefRef* _Null_unspecified)
128128
__attribute((swift_name("TRefRef.mutate(self:)")));
129-
extern void use_ConstTRef(ConstTRefRef)
129+
extern void use_ConstTRef(_Null_unspecified ConstTRefRef)
130130
__attribute((swift_name("ConstTRefRef.use(self:)")));
131+
132+
typedef NSString *MyString __attribute__((__swift_newtype__(struct)));
133+

test/IDE/print_clang_decls.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888

8989
// FOUNDATION-LABEL: {{^}}/// Aaa. NSArray. Bbb.{{$}}
9090
// FOUNDATION-NEXT: {{^}}class NSArray : NSObject {{{$}}
91+
// FOUNDATION-NEXT: init!(objects: UnsafePointer<AnyObject>?, count cnt: Int)
9192
// FOUNDATION-NEXT: subscript(idx: Int) -> Any { get }
9293

9394
// FOUNDATION-LABEL: {{^}}/// Aaa. NSRuncingMode. Bbb.{{$}}

test/Inputs/ObjCBridging/Appliances.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#endif
66

77
@interface APPRefrigerator : NSObject <NSCopying>
8-
-(nonnull instancetype)initWithTemperature:(double)temperature __attribute__((objc_designated_initializer));
8+
-(_Nonnull instancetype)initWithTemperature:(double)temperature __attribute__((objc_designated_initializer));
99
@property (nonatomic) double temperature;
1010
@end
1111

@@ -22,4 +22,4 @@
2222
@property (nonatomic,nonnull,readonly) id thing;
2323
@end
2424

25-
void takesNonStandardBlock(__attribute__((ns_returns_retained)) id (^)(void));
25+
void takesNonStandardBlock(__attribute__((__ns_returns_retained__)) _Null_unspecified id (^ _Null_unspecified)(void));

test/Inputs/clang-importer-sdk/usr/include/Foundation.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,21 @@ __attribute__((availability(ios,introduced=8.0)))
9494

9595
/// Aaa. NSArray. Bbb.
9696
@interface NSArray<ObjectType> : NSObject
97+
- (instancetype)initWithObjects:(const ObjectType _Nonnull [_Nullable])objects
98+
count:(NSUInteger)cnt NS_DESIGNATED_INITIALIZER;
9799
- (nonnull ObjectType)objectAtIndexedSubscript:(NSUInteger)idx;
98100
- description;
99-
+ (instancetype)arrayWithObjects:(const ObjectType _Nonnull[_Nullable])objects
100-
count:(NSUInteger)count;
101101
- (void)makeObjectsPerformSelector:(nonnull SEL)aSelector;
102102
- (void)makeObjectsPerformSelector:(nonnull SEL)aSelector withObject:(nullable ObjectType)anObject;
103103
- (void)makeObjectsPerformSelector:(nonnull SEL)aSelector withObject:(nullable ObjectType)anObject withObject:(nullable ObjectType)anotherObject;
104104
- (nonnull NSMutableArray<ObjectType> *)mutableCopy;
105105
@end
106106

107+
@interface NSArray<ObjectType>(NSArrayCreation)
108+
+ (instancetype)arrayWithObjects:(const ObjectType _Nonnull [_Nullable])objects
109+
count:(NSUInteger)cnt;
110+
@end
111+
107112
@interface NSArray (AddingObject)
108113
- (NSInteger)indexOfObject:(nonnull id)object;
109114
@end

test/SILGen/Inputs/objc_bridged_block_optionality_diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ typedef void (^HandlerBlock)(NSString *(^message)(void));
55
#pragma clang assume_nonnull end
66

77
/// Default handler for logging.
8-
extern HandlerBlock TheHandlerBlock;
8+
extern _Null_unspecified HandlerBlock TheHandlerBlock;

test/SILGen/Inputs/usr/include/BridgeTestFoundation.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#import "ObjectiveC.h"
22
#import "dispatch.h"
33

4+
#define NS_OPTIONS(type, name) type name; enum
5+
46
#pragma clang assume_nonnull begin
57

68
@interface NSString : NSObject<NSCopying>
@@ -10,10 +12,12 @@
1012

1113
@end
1214

15+
typedef NSString *NSErrorDomain;
16+
1317
@interface NSArray<ObjectType> : NSObject
1418

15-
- (instancetype)initWithObjects:(const ObjectType *)objects count:(int)count;
16-
- (instancetype)initWithArray:(NSArray<ObjectType>*)array;
19+
- (_Nonnull instancetype)initWithObjects:(const _Null_unspecified ObjectType * _Null_unspecified)objects count:(int)count;
20+
- (_Nonnull instancetype)initWithArray:(NSArray<ObjectType> *_Null_unspecified)array;
1721

1822
- (nonnull ObjectType)objectAtIndexedSubscript:(NSInteger)i;
1923

@@ -30,8 +34,8 @@
3034

3135
@interface Foo : NSObject
3236

33-
- (_Null_unspecified NSString*) foo;
34-
- (void)setFoo:(_Null_unspecified NSString *)s;
37+
- (NSString * _Null_unspecified ) foo;
38+
- (void)setFoo:(NSString * _Null_unspecified)s;
3539

3640
- (BOOL) zim;
3741
- (void) setZim: (BOOL)b;
@@ -57,10 +61,10 @@
5761

5862
@end
5963

60-
_Null_unspecified NSString *bar(void);
61-
void setBar(_Null_unspecified NSString *s);
64+
NSString * _Null_unspecified bar(void);
65+
void setBar(NSString * _Null_unspecified s);
6266

63-
_Null_unspecified NSString *NSStringFromString(_Null_unspecified NSString *s);
67+
NSString * _Null_unspecified NSStringFromString(NSString * _Null_unspecified s);
6468
NSString *NSStringFromClass(Class c);
6569

6670
#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
@@ -75,26 +79,26 @@ void useBool(_Bool x);
7579

7680
#pragma clang assume_nonnull end
7781

78-
void nonnullStringBlockResult(NSString *_Nonnull (^block)(void));
79-
void nonnullArrayBlockResult(NSArray *_Nonnull (^block)(void));
80-
void nonnullDictionaryBlockResult(NSDictionary *_Nonnull (^block)(void));
81-
void nonnullSetBlockResult(NSSet *_Nonnull (^block)(void));
82+
void nonnullStringBlockResult(NSString *_Nonnull (^ _Null_unspecified block)(void));
83+
void nonnullArrayBlockResult(NSArray *_Nonnull (^ _Null_unspecified block)(void));
84+
void nonnullDictionaryBlockResult(NSDictionary *_Nonnull (^ _Null_unspecified block)(void));
85+
void nonnullSetBlockResult(NSSet *_Nonnull (^ _Null_unspecified block)(void));
8286

83-
void noescapeBlock(__attribute__((noescape)) void (^block)(void));
84-
void escapeBlock(void (^block)(void));
85-
void noescapeBlock3(__attribute__((noescape)) void (^block)(NSString *s),
86-
__attribute__((noescape)) void (^block2)(NSString *s),
87-
NSString *f);
87+
void noescapeBlock(__attribute__((noescape)) void (^ _Null_unspecified block)(void));
88+
void escapeBlock(void (^ _Null_unspecified block)(void));
89+
void noescapeBlock3(__attribute__((noescape)) void (^ _Null_unspecified block)(NSString * _Null_unspecified s),
90+
__attribute__((noescape)) void (^ _Null_unspecified block2)(NSString * _Null_unspecified s),
91+
NSString * _Null_unspecified f);
8892

8993
void noescapeNonnullBlock(__attribute__((noescape)) void (^_Nonnull block)(void));
9094
void escapeNonnullBlock(void (^_Nonnull block)(void));
9195

92-
void noescapeBlockAlias(__attribute__((noescape)) dispatch_block_t block);
96+
void noescapeBlockAlias(__attribute__((noescape)) _Null_unspecified dispatch_block_t block);
9397
void noescapeNonnullBlockAlias(__attribute__((noescape)) _Nonnull dispatch_block_t block);
94-
void escapeBlockAlias(dispatch_block_t block);
98+
void escapeBlockAlias(_Null_unspecified dispatch_block_t block);
9599

96100
@interface ObjectWithSplitProperty : NSObject
97101
@property (nonatomic, setter=private_setFlagForSomething:) BOOL flagForSomething;
98102
@end
99103

100-
extern NSString * __nonnull (^ const __nonnull GlobalBlock)(NSString * __nonnull);
104+
extern NSString * _Nonnull (^ const _Nonnull GlobalBlock)(NSString * _Nonnull);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
@import Foundation;
3+
4+
@interface NSEntityDescription : NSObject
5+
@end
6+
7+
@interface NSManagedObjectContext : NSObject
8+
@end
9+
10+
@interface NSManagedObject : NSObject
11+
- (__kindof NSManagedObject *)initWithEntity:(NSEntityDescription *)entity
12+
insertIntoManagedObjectContext:(NSManagedObjectContext *)context;
13+
@property(nonatomic, readonly, strong) NSEntityDescription *entity;
14+
+ (NSEntityDescription *)entity;
15+
@end
16+

test/SILGen/Inputs/usr/include/ObjectiveC.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ typedef long NSInteger;
66
typedef struct _NSZone NSZone;
77

88
@protocol NSCopying
9-
- (id) copyWithZone: (nullable NSZone*)zone;
9+
- (_Null_unspecified id) copyWithZone: (nullable NSZone*)zone;
1010
@end
1111

12-
SEL sel_registerName(const char *);
12+
_Null_unspecified SEL sel_registerName(const char * _Null_unspecified);
1313

1414
@interface NSObject
15-
+ (NSObject*) alloc;
16-
- (NSObject*) init;
17-
+ (NSObject*) new;
15+
+ (NSObject* _Null_unspecified) alloc;
16+
- (NSObject* _Null_unspecified) init;
17+
+ (NSObject* _Null_unspecified) new;
1818
+ (void) load;
1919
+ (void) initialize;
2020

21-
- (id)performSelector:(SEL)selector withObject:(id)object;
21+
- (_Null_unspecified id)performSelector:(_Null_unspecified SEL)selector withObject:(_Null_unspecified id)object;
2222

23-
@property (readonly, copy) NSString *description;
23+
@property (readonly, copy) NSString * _Null_unspecified description;
2424

25-
@property NSString *stringProperty;
25+
@property NSString * _Null_unspecified stringProperty;
2626

27-
@property Class classProp;
27+
@property Class _Null_unspecified classProp;
2828
@end
2929

3030
#define NS_RETURNS_INNER_POINTER __attribute__((objc_returns_inner_pointer))

test/SILGen/Inputs/usr/include/module.map

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module AppKit {
2626
header "AppKit.h"
2727
export *
2828
}
29+
module CoreData {
30+
header "CoreData.h"
31+
export *
32+
}
2933
module Dispatch {
3034
header "dispatch.h"
3135
export *
@@ -35,11 +39,6 @@ module objc_extensions_helper {
3539
header "objc_extensions_helper.h"
3640
}
3741

38-
module Newtype {
39-
header "newtype.h"
40-
export *
41-
}
42-
4342
module NonNilTest {
4443
header "NonNilTest.h"
4544
export *

test/SILGen/c_materializeForSet_linkage.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-sil-ownership | %FileCheck %s
2-
3-
// REQUIRES: objc_interop
1+
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-sil-ownership -enable-objc-interop | %FileCheck %s
42

53
import AppKit
64

test/SILGen/cf.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
// RUN: %target-swift-emit-silgen -module-name cf -import-cf-types -sdk %S/Inputs %s -o - | %FileCheck %s
3-
4-
// REQUIRES: objc_interop
1+
// RUN: %target-swift-emit-silgen -module-name cf -enable-objc-interop -import-cf-types -sdk %S/Inputs %s -o - | %FileCheck %s
52

63
import CoreCooling
74

0 commit comments

Comments
 (0)