summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2015-02-25 20:09:06 +0000
committerBen Langmuir <blangmuir@apple.com>2015-02-25 20:09:06 +0000
commit443aa4b4b0cb7098fdf6ae238ebbbed3f64b4719 (patch)
treeabf52cf459431a6bd388e0ebebd0b3bdcc09f852 /clang/test/SemaObjC
parentdcc84db2641eaff6efece8502ccc5f3863ef9356 (diff)
downloadbcm5719-llvm-443aa4b4b0cb7098fdf6ae238ebbbed3f64b4719.tar.gz
bcm5719-llvm-443aa4b4b0cb7098fdf6ae238ebbbed3f64b4719.zip
Allow (Object *)kMyGlobalCFObj casts without bridging
Previously we allowed these casts only for constants declared in system headers, which we assume are retain/release-neutral. Now also allow them for constants in user headers, treating them as +0. Practically, this means that we will now allow: id x = (id)kMyGlobalConst; But unlike with system headers we cannot mix them with +1 values: id y = (id)(b ? kMyGlobalConst : [Obj newValAtPlusOne]); // error id z = (id)(b ? kSystemGlobalConst: [Obj newValAtPlusOne]); // OK Thanks to John for suggesting this improvement. llvm-svn: 230534
Diffstat (limited to 'clang/test/SemaObjC')
-rw-r--r--clang/test/SemaObjC/arc-dict-bridged-cast.m13
-rw-r--r--clang/test/SemaObjC/arc-unbridged-cast.m7
2 files changed, 10 insertions, 10 deletions
diff --git a/clang/test/SemaObjC/arc-dict-bridged-cast.m b/clang/test/SemaObjC/arc-dict-bridged-cast.m
index e00c47fca39..e683343cd07 100644
--- a/clang/test/SemaObjC/arc-dict-bridged-cast.m
+++ b/clang/test/SemaObjC/arc-dict-bridged-cast.m
@@ -28,19 +28,12 @@ id CFBridgingRelease(CFTypeRef __attribute__((cf_consumed)) X);
NSMutableString *test() {
NSDictionary *infoDictionary;
- infoDictionary[kCFBundleNameKey] = 0; // expected-error {{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or Objective-C pointer type}} \
- // expected-error {{implicit conversion of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type '__strong id<NSCopying>' requires a bridged cast}} \
- // expected-note {{use __bridge to convert directly (no change in ownership)}} \
- // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
+ infoDictionary[kCFBundleNameKey] = 0; // expected-error {{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or Objective-C pointer type}}
return infoDictionary[CFStringCreateMutable(((void*)0), 100)]; // expected-error {{indexing expression is invalid because subscript type 'CFMutableStringRef' (aka 'struct __CFString *') is not an integral or Objective-C pointer type}} \
// expected-error {{implicit conversion of C pointer type 'CFMutableStringRef' (aka 'struct __CFString *') to Objective-C pointer type '__strong id<NSCopying>' requires a bridged cast}} \
// expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFMutableStringRef' (aka 'struct __CFString *') into ARC}}
}
-// CHECK: fix-it:"{{.*}}":{31:18-31:18}:"(__bridge __strong id<NSCopying>)("
-// CHECK: fix-it:"{{.*}}":{31:34-31:34}:")"
-// CHECK: fix-it:"{{.*}}":{31:18-31:18}:"CFBridgingRelease("
-// CHECK: fix-it:"{{.*}}":{31:34-31:34}:")"
-// CHECK: fix-it:"{{.*}}":{35:25-35:25}:"CFBridgingRelease("
-// CHECK: fix-it:"{{.*}}":{35:63-35:63}:")"
+// CHECK: fix-it:"{{.*}}":{32:25-32:25}:"CFBridgingRelease("
+// CHECK: fix-it:"{{.*}}":{32:63-32:63}:")"
diff --git a/clang/test/SemaObjC/arc-unbridged-cast.m b/clang/test/SemaObjC/arc-unbridged-cast.m
index 6a39e707717..3c0e3f28854 100644
--- a/clang/test/SemaObjC/arc-unbridged-cast.m
+++ b/clang/test/SemaObjC/arc-unbridged-cast.m
@@ -32,15 +32,20 @@ CFStringRef auditedString(void);
CFStringRef auditedCreateString(void);
#pragma clang arc_cf_code_audited end
+extern const CFStringRef kUserConst;
+
void test1(int cond) {
id x;
x = (id) auditedString();
+ x = (id) kUserConst;
x = (id) (cond ? auditedString() : (void*) 0);
x = (id) (cond ? (void*) 0 : auditedString());
x = (id) (cond ? (CFStringRef) @"help" : auditedString());
+ x = (id) (cond ? (CFStringRef) @"help" : kUserConst);
x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+ x = (id) (cond ? unauditedString() : kUserConst); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
@@ -68,11 +73,13 @@ void test1(int cond) {
x = (id) (cond ? [object makeString] : (void*) 0);
x = (id) (cond ? (void*) 0 : [object makeString]);
x = (id) (cond ? (CFStringRef) @"help" : [object makeString]);
+ x = (id) (cond ? kUserConst : [object makeString]);
x = (id) [object newString];
x = (id) (cond ? [object newString] : (void*) 0);
x = (id) (cond ? (void*) 0 : [object newString]);
x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable
+ x = (id) (cond ? kUserConst : [object newString]); // expected-error{{requires a bridged cast}} expected-note{{use __bridge to}} expected-note{{use CFBridgingRelease call to}}
}
// rdar://problem/10246264
OpenPOWER on IntegriCloud