aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-04 23:52:23 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-04 23:52:23 +0000
commit50687314f87b67073c202fe46d84d12fb55e25cf (patch)
tree491dbe2cec61beaa39e868fd028e929b6e396df9 /test
parent033a9c0804f48119a03b73a2af42a04d4d0294ce (diff)
Teach format string checking about compile-time CFString constants.
Within the guts of CheckFormatHandler, the IsObjCLiteral flag was being used in two ways: to see if null bytes were allowed, and to see if the '%@' specifier is allowed.* The former usage has been changed to an explicit test and the latter pushed down to CheckPrintfHandler and renamed ObjCContext, since it applies to CFStrings as well. * This also changes how wide chars are interpreted; in OS X Foundation, the wide character type is 'unichar', a typedef for short, rather than wchar_t. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaObjC/format-strings-objc.m19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m
index c1285b2e13..043cb5d8d2 100644
--- a/test/SemaObjC/format-strings-objc.m
+++ b/test/SemaObjC/format-strings-objc.m
@@ -31,6 +31,12 @@ extern void *_NSConstantStringClassReference;
typedef const struct __CFString * CFStringRef;
extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2)));
+#define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
+
+// This function is used instead of the builtin if -fno-constant-cfstrings.
+// The definition on Mac OS X is NOT annotated with format_arg as of 10.7,
+// but if it were, we want the same checking behavior as with the builtin.
+extern CFStringRef __CFStringMakeConstantString(const char *) __attribute__((format_arg(1)));
int printf(const char * restrict, ...) ;
@@ -52,6 +58,7 @@ void rdar_7068334() {
long long test = 500;
printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
+ CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
}
// <rdar://problem/7697748>
@@ -72,7 +79,7 @@ extern void MyCFStringCreateWithFormat(CFStringRef format, ...) __attribute__((f
void check_mylog() {
MyNSLog(@"%@"); // expected-warning {{more '%' conversions than data arguments}}
- // FIXME: find a way to test CFString too, but I don't know how to create constant CFString.
+ MyCFStringCreateWithFormat(CFSTR("%@")); // expected-warning {{more '%' conversions than data arguments}}
}
// PR 10275 - format function attribute isn't checked in Objective-C methods
@@ -159,8 +166,12 @@ void test_percent_C() {
}
// Test that %@ works with toll-free bridging (<rdar://problem/10814120>).
-void test_toll_free_bridging(CFStringRef x) {
+void test_toll_free_bridging(CFStringRef x, id y) {
NSLog(@"%@", x); // no-warning
+ CFStringCreateWithFormat(CFSTR("%@"), x); // no-warning
+
+ NSLog(@"%@", y); // no-warning
+ CFStringCreateWithFormat(CFSTR("%@"), y); // no-warning
}
@interface Bar
@@ -195,3 +206,7 @@ int rdar11049844() {
printf("%p", x); // no-warning
}
+void test_nonBuiltinCFStrings() {
+ CFStringCreateWithFormat(__CFStringMakeConstantString("%@"), 1); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
+}
+