mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-25 22:38:56 -04:00

expression Clang emits invalid protocol metadata when a @protocol expression is used with a forward-declared protocol. The protocol metadata is missing protocol conformance list of the protocol since we don't have access to the definition of it in the compiled translation unit. The linker then might end up picking the invalid metadata when linking which will lead to incorrect runtime protocol conformance checks. This commit makes sure that Clang fails to compile code that uses a @protocol expression with a forward-declared protocol. This ensures that Clang does not emit invalid protocol metadata. I added an extra assert in CodeGen to ensure that this kind of issue won't happen in other places. rdar://32787811 Differential Revision: https://reviews.llvm.org/D49462 llvm-svn: 340102
35 lines
1.1 KiB
Objective-C
35 lines
1.1 KiB
Objective-C
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
@class Protocol;
|
|
|
|
@protocol fproto; // expected-note {{'fproto' declared here}}
|
|
|
|
@protocol p1
|
|
@end
|
|
|
|
@class cl;
|
|
|
|
int main()
|
|
{
|
|
Protocol *proto = @protocol(p1);
|
|
Protocol *fproto = @protocol(fproto); // expected-error {{@protocol is using a forward protocol declaration of 'fproto'}}
|
|
Protocol *pp = @protocol(i); // expected-error {{cannot find protocol declaration for 'i'}}
|
|
Protocol *p1p = @protocol(cl); // expected-error {{cannot find protocol declaration for 'cl'}}
|
|
}
|
|
|
|
// rdar://17768630
|
|
@protocol SuperProtocol; // expected-note {{'SuperProtocol' declared here}}
|
|
@protocol TestProtocol; // expected-note {{'TestProtocol' declared here}}
|
|
|
|
@interface I
|
|
- (int) conformsToProtocol : (Protocol *)protocl;
|
|
@end
|
|
|
|
int doesConform(id foo) {
|
|
return [foo conformsToProtocol:@protocol(TestProtocol)]; // expected-error {{@protocol is using a forward protocol declaration of 'TestProtocol'}}
|
|
}
|
|
|
|
int doesConformSuper(id foo) {
|
|
return [foo conformsToProtocol:@protocol(SuperProtocol)]; // expected-error {{@protocol is using a forward protocol declaration of 'SuperProtocol'}}
|
|
}
|