| 1 |
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}} |
| 2 |
// RUN: rm -rf %t |
| 3 |
// RUN: split-file %s %t |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-extension.m |
| 5 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-extension.m \ |
| 6 |
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 7 |
|
| 8 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-ivars-number.m |
| 9 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-ivars-number.m \ |
| 10 |
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 11 |
|
| 12 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-methods-protocols.m |
| 13 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-methods-protocols.m \ |
| 14 |
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 15 |
|
| 16 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-subclass.m |
| 17 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-subclass.m \ |
| 18 |
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 19 |
|
| 20 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-implementation.m |
| 21 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-implementation.m \ |
| 22 |
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 23 |
|
| 24 |
// Same class extensions with the same ivars but from different modules aren't considered |
| 25 |
// an error and they are merged together. Test that differences in extensions and/or ivars |
| 26 |
// are still reported as errors. |
| 27 |
|
| 28 |
//--- include/Interfaces.h |
| 29 |
@interface NSObject @end |
| 30 |
@interface ObjCInterface : NSObject |
| 31 |
@end |
| 32 |
@interface ObjCInterfaceLevel2 : ObjCInterface |
| 33 |
@end |
| 34 |
|
| 35 |
@protocol Protocol1 @end |
| 36 |
@protocol Protocol2 @end |
| 37 |
|
| 38 |
//--- include/IvarsInExtensions.h |
| 39 |
#import <Interfaces.h> |
| 40 |
@interface ObjCInterface() { |
| 41 |
int ivarName; |
| 42 |
} |
| 43 |
@end |
| 44 |
@interface ObjCInterfaceLevel2() { |
| 45 |
int bitfieldIvarName: 3; |
| 46 |
} |
| 47 |
@end |
| 48 |
|
| 49 |
//--- include/IvarsInExtensionsWithMethodsProtocols.h |
| 50 |
#import <Interfaces.h> |
| 51 |
@interface ObjCInterface() { |
| 52 |
int methodRelatedIvar; |
| 53 |
} |
| 54 |
- (void)test; |
| 55 |
@end |
| 56 |
@interface ObjCInterfaceLevel2() <Protocol1> { |
| 57 |
int protocolRelatedIvar; |
| 58 |
} |
| 59 |
@end |
| 60 |
|
| 61 |
//--- include/IvarInImplementation.h |
| 62 |
#import <Interfaces.h> |
| 63 |
@implementation ObjCInterface { |
| 64 |
int ivarName; |
| 65 |
} |
| 66 |
@end |
| 67 |
|
| 68 |
//--- include/module.modulemap |
| 69 |
module Interfaces { |
| 70 |
header "Interfaces.h" |
| 71 |
export * |
| 72 |
} |
| 73 |
module IvarsInExtensions { |
| 74 |
header "IvarsInExtensions.h" |
| 75 |
export * |
| 76 |
} |
| 77 |
module IvarsInExtensionsWithMethodsProtocols { |
| 78 |
header "IvarsInExtensionsWithMethodsProtocols.h" |
| 79 |
export * |
| 80 |
} |
| 81 |
module IvarInImplementation { |
| 82 |
header "IvarInImplementation.h" |
| 83 |
export * |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
//--- test-mismatch-in-extension.m |
| 88 |
// Different ivars with the same name aren't mergeable and constitute an error. |
| 89 |
#import <Interfaces.h> |
| 90 |
@interface ObjCInterface() { |
| 91 |
float ivarName; // expected-note {{previous definition is here}} |
| 92 |
} |
| 93 |
@end |
| 94 |
@interface ObjCInterfaceLevel2() { |
| 95 |
int bitfieldIvarName: 5; // expected-note {{previous definition is here}} |
| 96 |
} |
| 97 |
@end |
| 98 |
#import <IvarsInExtensions.h> |
| 99 |
// [email protected]:* {{instance variable is already declared}} |
| 100 |
// [email protected]:* {{instance variable is already declared}} |
| 101 |
@implementation ObjCInterfaceLevel2 |
| 102 |
@end |
| 103 |
|
| 104 |
|
| 105 |
//--- test-mismatch-in-ivars-number.m |
| 106 |
// Extensions with different amount of ivars aren't considered to be the same. |
| 107 |
#import <Interfaces.h> |
| 108 |
@interface ObjCInterface() { |
| 109 |
int ivarName; // expected-note {{previous definition is here}} |
| 110 |
float anotherIvar; |
| 111 |
} |
| 112 |
@end |
| 113 |
#import <IvarsInExtensions.h> |
| 114 |
// [email protected]:* {{instance variable is already declared}} |
| 115 |
@implementation ObjCInterface |
| 116 |
@end |
| 117 |
|
| 118 |
|
| 119 |
//--- test-mismatch-in-methods-protocols.m |
| 120 |
// Extensions with different methods or protocols aren't considered to be the same. |
| 121 |
#import <Interfaces.h> |
| 122 |
@interface ObjCInterface() { |
| 123 |
int methodRelatedIvar; // expected-note {{previous definition is here}} |
| 124 |
} |
| 125 |
- (void)differentTest; |
| 126 |
@end |
| 127 |
@interface ObjCInterfaceLevel2() <Protocol2> { |
| 128 |
int protocolRelatedIvar; // expected-note {{previous definition is here}} |
| 129 |
} |
| 130 |
@end |
| 131 |
#import <IvarsInExtensionsWithMethodsProtocols.h> |
| 132 |
// [email protected]:* {{instance variable is already declared}} |
| 133 |
// [email protected]:* {{instance variable is already declared}} |
| 134 |
@implementation ObjCInterfaceLevel2 |
| 135 |
@end |
| 136 |
|
| 137 |
|
| 138 |
//--- test-redecl-in-subclass.m |
| 139 |
// Ivar in superclass extension is not added to a subclass, so the ivar with |
| 140 |
// the same name in subclass extension is not considered a redeclaration. |
| 141 |
// expected-no-diagnostics |
| 142 |
#import <Interfaces.h> |
| 143 |
@interface ObjCInterfaceLevel2() { |
| 144 |
float ivarName; |
| 145 |
} |
| 146 |
@end |
| 147 |
#import <IvarsInExtensions.h> |
| 148 |
@implementation ObjCInterfaceLevel2 |
| 149 |
@end |
| 150 |
|
| 151 |
|
| 152 |
//--- test-redecl-in-implementation.m |
| 153 |
// Ivar redeclaration in `@implementation` is always an error and never mergeable. |
| 154 |
#import <IvarsInExtensions.h> |
| 155 |
@interface ObjCInterface() { |
| 156 |
int triggerExtensionIvarDeserialization; |
| 157 |
} |
| 158 |
@end |
| 159 |
#import <IvarInImplementation.h> |
| 160 |
#if __has_feature(modules) |
| 161 |
// [email protected]:* {{instance variable is already declared}} |
| 162 |
// [email protected]:* {{previous definition is here}} |
| 163 |
#else |
| 164 |
// [email protected]:* {{instance variable is already declared}} |
| 165 |
// [email protected]:* {{previous definition is here}} |
| 166 |
#endif |