mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 12:46:47 +00:00

We have a new policy in place making links to private resources something we try to avoid in source and test files. Normally, we'd organically switch to the new policy rather than make a sweeping change across a project. However, Clang is in a somewhat special circumstance currently: recently, I've had several new contributors run into rdar links around test code which their patch was changing the behavior of. This turns out to be a surprisingly bad experience, especially for newer folks, for a handful of reasons: not understanding what the link is and feeling intimidated by it, wondering whether their changes are actually breaking something important to a downstream in some way, having to hunt down strangers not involved with the patch to impose on them for help, accidental pressure from asking for potentially private IP to be made public, etc. Because folks run into these links entirely by chance (through fixing bugs or working on new features), there's not really a set of problematic links to focus on -- all of the links have basically the same potential for causing these problems. As a result, this is an omnibus patch to remove all such links. This was not a mechanical change; it was done by manually searching for rdar, radar, radr, and other variants to find all the various problematic links. From there, I tried to retain or reword the surrounding comments so that we would lose as little context as possible. However, because most links were just a plain link with no supporting context, the majority of the changes are simple removals. Differential Review: https://reviews.llvm.org/D158071
102 lines
3.6 KiB
Objective-C
102 lines
3.6 KiB
Objective-C
// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
|
|
|
|
//====------------------------------------------------------------====//
|
|
// Test deprecated direct usage of the 'isa' pointer.
|
|
//====------------------------------------------------------------====//
|
|
|
|
typedef unsigned long NSUInteger;
|
|
|
|
typedef struct objc_object {
|
|
struct objc_class *isa;
|
|
} *id;
|
|
|
|
@interface NSObject {
|
|
id firstobj;
|
|
struct objc_class *isa;
|
|
}
|
|
- (id)performSelector:(SEL)aSelector;;
|
|
@end
|
|
@interface Whatever : NSObject
|
|
+self;
|
|
-(id)foo;
|
|
@end
|
|
|
|
static void func(void) {
|
|
|
|
id x;
|
|
|
|
[(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
[x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
|
|
Whatever *y;
|
|
|
|
// GCC allows this, with the following warning:
|
|
// instance variable 'isa' is @protected; this will be a hard error in the future
|
|
//
|
|
// FIXME: see if we can avoid the warning that follows the error.
|
|
[(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
|
|
expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
|
|
[y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
|
|
expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
|
|
}
|
|
|
|
// If an ivar is (1) the first ivar in a root class and (2) named `isa`,
|
|
// then it should get the same warnings that id->isa gets.
|
|
|
|
@interface BaseClass {
|
|
@public
|
|
Class isa; // expected-note 4 {{instance variable is declared here}}
|
|
}
|
|
@end
|
|
|
|
@interface OtherClass {
|
|
@public
|
|
id firstIvar;
|
|
Class isa; // note, not first ivar;
|
|
}
|
|
@end
|
|
|
|
@interface Subclass : BaseClass @end
|
|
|
|
@interface SiblingClass : BaseClass @end
|
|
|
|
@interface Root @end
|
|
|
|
@interface hasIsa : Root {
|
|
@public
|
|
Class isa; // note, isa is not in root class
|
|
}
|
|
@end
|
|
|
|
@implementation Subclass
|
|
-(void)method {
|
|
hasIsa *u;
|
|
id v;
|
|
BaseClass *w;
|
|
Subclass *x;
|
|
SiblingClass *y;
|
|
OtherClass *z;
|
|
(void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
(void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
(void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
(void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
|
(void)z->isa;
|
|
(void)u->isa;
|
|
|
|
w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}}
|
|
}
|
|
@end
|
|
|
|
// Test for introspection of Objective-C pointers via bitmasking.
|
|
|
|
void testBitmasking(NSObject *p) {
|
|
(void) (((NSUInteger) p) & 0x1); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
(void) (0x1 & ((NSUInteger) p)); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
(void) (((NSUInteger) p) ^ 0x1); // no-warning
|
|
(void) (0x1 ^ ((NSUInteger) p)); // no-warning
|
|
(void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection-performSelector"
|
|
(void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // no-warning
|
|
#pragma clang diagnostic pop
|
|
} |