brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.9 KiB · 6dec296 Raw
360 lines · plain
1// RUN: rm -rf %t2// RUN: split-file %s %t3 4// Build first header file5// RUN: echo "#define FIRST" >> %t/include/first.h6// RUN: cat %t/test.m        >> %t/include/first.h7// RUN: echo "#undef FIRST"  >> %t/include/first.h8 9// Build second header file10// RUN: echo "#define SECOND" >> %t/include/second.h11// RUN: cat %t/test.m         >> %t/include/second.h12// RUN: echo "#undef SECOND"  >> %t/include/second.h13 14// Test that each header can compile15// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/first.h -fblocks -fobjc-arc16// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/second.h -fblocks -fobjc-arc17 18// Run test19// RUN: %clang_cc1 -I%t/include -verify %t/test.m -fblocks -fobjc-arc \20// RUN:            -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache21 22// Run the same test with second.h being modular23// RUN: cat %t/include/second.modulemap >> %t/include/module.modulemap24// RUN: %clang_cc1 -I%t/include -verify %t/test.m -fblocks -fobjc-arc -DTEST_MODULAR=1 \25// RUN:            -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache26 27// In non-modular case we ignore protocol redefinitions. But with modules28// previous definition can come from a hidden [sub]module. And in this case we29// allow a new definition if it is equivalent to the hidden one.30//31// This test case is to verify equivalence checks.32 33//--- include/common.h34#ifndef COMMON_H35#define COMMON_H36@protocol CommonProtocol @end37@protocol ExtraProtocol @end38#endif39 40//--- include/first-empty.h41//--- include/module.modulemap42module Common {43  header "common.h"44  export *45}46module First {47  module Empty {48    header "first-empty.h"49  }50  module Hidden {51    header "first.h"52    export *53  }54}55//--- include/second.modulemap56module Second {57  header "second.h"58  export *59}60 61//--- test.m62#if defined(FIRST) || defined(SECOND)63# include "common.h"64#endif65 66#if !defined(FIRST) && !defined(SECOND)67# include "first-empty.h"68# include "second.h"69#endif70 71#if defined(FIRST)72@protocol CompareForwardDeclaration1;73@protocol CompareForwardDeclaration2<CommonProtocol> @end74#elif defined(SECOND)75@protocol CompareForwardDeclaration1<CommonProtocol> @end76@protocol CompareForwardDeclaration2;77#else78id<CompareForwardDeclaration1> compareForwardDeclaration1;79id<CompareForwardDeclaration2> compareForwardDeclaration2;80#endif81 82#if defined(FIRST)83@protocol CompareMatchingConformingProtocols<CommonProtocol> @end84@protocol ForwardProtocol;85@protocol CompareMatchingConformingForwardProtocols<ForwardProtocol> @end86 87@protocol CompareProtocolPresence1<CommonProtocol> @end88@protocol CompareProtocolPresence2 @end89 90@protocol CompareDifferentProtocols<CommonProtocol> @end91@protocol CompareProtocolOrder<CommonProtocol, ExtraProtocol> @end92#elif defined(SECOND)93@protocol CompareMatchingConformingProtocols<CommonProtocol> @end94@protocol ForwardProtocol @end95@protocol CompareMatchingConformingForwardProtocols<ForwardProtocol> @end96 97@protocol CompareProtocolPresence1 @end98@protocol CompareProtocolPresence2<CommonProtocol> @end99 100@protocol CompareDifferentProtocols<ExtraProtocol> @end101@protocol CompareProtocolOrder<ExtraProtocol, CommonProtocol> @end102#else103id<CompareMatchingConformingProtocols> compareMatchingConformingProtocols;104id<CompareMatchingConformingForwardProtocols> compareMatchingConformingForwardProtocols;105 106id<CompareProtocolPresence1> compareProtocolPresence1;107// expected-error@first.h:* {{'CompareProtocolPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1 referenced protocol}}108#ifdef TEST_MODULAR109// expected-note@second.h:* {{but in 'Second' found 0 referenced protocols}}110#else111// expected-note@second.h:* {{but in definition here found 0 referenced protocols}}112#endif113id<CompareProtocolPresence2> compareProtocolPresence2;114// expected-error@first.h:* {{'CompareProtocolPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 0 referenced protocols}}115// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 1 referenced protocol}}116 117id<CompareDifferentProtocols> compareDifferentProtocols;118// expected-error@first.h:* {{'CompareDifferentProtocols' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}119// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 1st referenced protocol with different name 'ExtraProtocol'}}120id<CompareProtocolOrder> compareProtocolOrder;121// expected-error@first.h:* {{'CompareProtocolOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 1st referenced protocol with name 'CommonProtocol'}}122// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 1st referenced protocol with different name 'ExtraProtocol'}}123#endif124 125#if defined(FIRST)126@protocol CompareMatchingMethods127- (float)matchingMethod:(int)arg;128@end129 130@protocol CompareMethodPresence1131- (void)presenceMethod1;132@end133@protocol CompareMethodPresence2134@end135 136@protocol CompareMethodName137- (void)methodNameA;138@end139 140@protocol CompareMethodArgCount141- (void)methodArgCount:(int)arg0 :(int)arg1;142@end143@protocol CompareMethodArgName144- (void)methodArgName:(int)argNameA;145@end146@protocol CompareMethodArgType147- (void)methodArgType:(int)argType;148@end149 150@protocol CompareMethodReturnType151- (int)methodReturnType;152@end153 154@protocol CompareMethodOrder155- (void)methodOrderFirst;156- (void)methodOrderSecond;157@end158 159@protocol CompareMethodClassInstance160- (void)methodClassInstance;161@end162 163@protocol CompareMethodRequirednessExplicit164@optional165- (void)methodRequiredness;166@end167@protocol CompareMethodRequirednessDefault168// @required is default169- (void)methodRequiredness;170@end171#elif defined(SECOND)172@protocol CompareMatchingMethods173- (float)matchingMethod:(int)arg;174@end175 176@protocol CompareMethodPresence1177@end178@protocol CompareMethodPresence2179- (void)presenceMethod2;180@end181 182@protocol CompareMethodName183- (void)methodNameB;184@end185 186@protocol CompareMethodArgCount187- (void)methodArgCount:(int)arg0;188@end189@protocol CompareMethodArgName190- (void)methodArgName:(int)argNameB;191@end192@protocol CompareMethodArgType193- (void)methodArgType:(float)argType;194@end195 196@protocol CompareMethodReturnType197- (float)methodReturnType;198@end199 200@protocol CompareMethodOrder201- (void)methodOrderSecond;202- (void)methodOrderFirst;203@end204 205@protocol CompareMethodClassInstance206+ (void)methodClassInstance;207@end208 209@protocol CompareMethodRequirednessExplicit210@required211- (void)methodRequiredness;212@end213@protocol CompareMethodRequirednessDefault214@required215- (void)methodRequiredness;216@end217#else218id<CompareMatchingMethods> compareMatchingMethods; // no error219id<CompareMethodPresence1> compareMethodPresence1;220// expected-error@first.h:* {{'CompareMethodPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method}}221// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found end of class}}222id<CompareMethodPresence2> compareMethodPresence2;223// expected-error@first.h:* {{'CompareMethodPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found end of class}}224// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method}}225id<CompareMethodName> compareMethodName;226// expected-error@first.h:* {{'CompareMethodName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodNameA'}}227// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found different method 'methodNameB'}}228 229id<CompareMethodArgCount> compareMethodArgCount;230// expected-error@first.h:* {{'CompareMethodArgCount' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgCount::' that has 2 parameters}}231// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method 'methodArgCount:' that has 1 parameter}}232id<CompareMethodArgName> compareMethodArgName;233// expected-error@first.h:* {{'CompareMethodArgName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgName:' with 1st parameter named 'argNameA'}}234// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method 'methodArgName:' with 1st parameter named 'argNameB'}}235id<CompareMethodArgType> compareMethodArgType;236// expected-error@first.h:* {{'CompareMethodArgType' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodArgType:' with 1st parameter of type 'int'}}237// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method 'methodArgType:' with 1st parameter of type 'float'}}238 239id<CompareMethodReturnType> compareMethodReturnType;240// expected-error@first.h:* {{'CompareMethodReturnType' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodReturnType' with return type 'int'}}241// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method 'methodReturnType' with different return type 'float'}}242 243id<CompareMethodOrder> compareMethodOrder;244// expected-error@first.h:* {{'CompareMethodOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found method 'methodOrderFirst'}}245// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found different method 'methodOrderSecond'}}246id<CompareMethodClassInstance> compareMethodClassInstance;247// expected-error@first.h:* {{'CompareMethodClassInstance' has different definitions in different modules; first difference is definition in module 'First.Hidden' found instance method 'methodClassInstance'}}248// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found method 'methodClassInstance' as class method}}249 250id<CompareMethodRequirednessExplicit> compareMethodRequirednessExplicit;251// expected-error@first.h:* {{'CompareMethodRequirednessExplicit' has different definitions in different modules; first difference is definition in module 'First.Hidden' found 'optional' method control}}252// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found 'required' method control}}253id<CompareMethodRequirednessDefault> compareMethodRequirednessDefault; // no error254#endif255 256#if defined(FIRST)257@protocol CompareMatchingProperties258@property int matchingPropName;259@end260 261@protocol ComparePropertyPresence1262@property int propPresence1;263@end264@protocol ComparePropertyPresence2265@end266 267@protocol ComparePropertyName268@property int propNameA;269@end270 271@protocol ComparePropertyType272@property int propType;273@end274 275@protocol ComparePropertyOrder276@property int propOrderX;277@property int propOrderY;278@end279 280@protocol CompareMatchingPropertyAttributes281@property (nonatomic, assign) int matchingProp;282@end283@protocol ComparePropertyAttributes284@property (nonatomic) int propAttributes;285@end286// Edge cases.287@protocol CompareFirstImplAttribute288@property int firstImplAttribute;289@end290@protocol CompareLastImplAttribute291// Cannot test with protocols 'direct' attribute because it's not allowed.292@property (class) int lastImplAttribute;293@end294#elif defined(SECOND)295@protocol CompareMatchingProperties296@property int matchingPropName;297@end298 299@protocol ComparePropertyPresence1300@end301@protocol ComparePropertyPresence2302@property int propPresence2;303@end304 305@protocol ComparePropertyName306@property int propNameB;307@end308 309@protocol ComparePropertyType310@property float propType;311@end312 313@protocol ComparePropertyOrder314@property int propOrderY;315@property int propOrderX;316@end317 318@protocol CompareMatchingPropertyAttributes319@property (assign, nonatomic) int matchingProp;320@end321@protocol ComparePropertyAttributes322@property (atomic) int propAttributes;323@end324// Edge cases.325@protocol CompareFirstImplAttribute326@property (readonly) int firstImplAttribute;327@end328@protocol CompareLastImplAttribute329@property int lastImplAttribute;330@end331#else332id<CompareMatchingProperties> compareMatchingProperties;333id<ComparePropertyPresence1> comparePropertyPresence1;334// expected-error@first.h:* {{'ComparePropertyPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property}}335// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found end of class}}336id<ComparePropertyPresence2> comparePropertyPresence2;337// expected-error@first.h:* {{'ComparePropertyPresence2' has different definitions in different modules; first difference is definition in module 'First.Hidden' found end of class}}338// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property}}339id<ComparePropertyName> comparePropertyName;340// expected-error@first.h:* {{'ComparePropertyName' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propNameA'}}341// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'propNameB'}}342id<ComparePropertyType> comparePropertyType;343// expected-error@first.h:* {{'ComparePropertyType' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propType' with type 'int'}}344// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'propType' with type 'float'}}345id<ComparePropertyOrder> comparePropertyOrder;346// expected-error@first.h:* {{'ComparePropertyOrder' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propOrderX'}}347// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'propOrderY'}}348 349id<CompareMatchingPropertyAttributes> compareMatchingPropertyAttributes;350id<ComparePropertyAttributes> comparePropertyAttributes;351// expected-error@first.h:* {{'ComparePropertyAttributes' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'propAttributes' with 'nonatomic' attribute}}352// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'propAttributes' with different 'nonatomic' attribute}}353id<CompareFirstImplAttribute> compareFirstImplAttribute;354// expected-error@first.h:* {{'CompareFirstImplAttribute' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'firstImplAttribute' with default 'readonly' attribute}}355// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'firstImplAttribute' with different 'readonly' attribute}}356id<CompareLastImplAttribute> compareLastImplAttribute;357// expected-error@first.h:* {{'CompareLastImplAttribute' has different definitions in different modules; first difference is definition in module 'First.Hidden' found property 'lastImplAttribute' with 'class' attribute}}358// expected-note-re@second.h:* {{but in {{'Second'|definition here}} found property 'lastImplAttribute' with different 'class' attribute}}359#endif360