#include <stdarg.h>
typedef signed char BOOL;
typedef unsigned int NSUInteger;
typedef long NSInteger;
@class NSString, Protocol;
extern void NSLog(NSString *format, ...);
extern void NSLogv(NSString *format, va_list args);
typedef struct _NSZone NSZone;
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
@protocol NSObject - (BOOL)isEqual:(id)object; @end
@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
@interface NSObject <NSObject> {} @end
typedef float CGFloat;
@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
- (NSUInteger)length;
+(instancetype)stringWithFormat:(NSString *)fmt, ...
__attribute__((format(__NSString__, 1, 2)));
@end
@interface NSSimpleCString : NSString {} @end
@interface NSConstantString : NSSimpleCString @end
extern void *_NSConstantStringClassReference;
@interface NSAttributedString : NSObject
+(instancetype)stringWithFormat:(NSAttributedString *)fmt, ...
__attribute__((format(__NSString__, 1, 2)));
@end
typedef const struct __CFString * CFStringRef;
extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2)));
#define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
extern CFStringRef __CFStringMakeConstantString(const char *);
int printf(const char * restrict, ...) ;
void check_nslog(unsigned k) {
NSLog(@"%d%%", k); NSLog(@"%s%lb%d", "unix", 10, 20); }
extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2)));
extern void NSLog3(const char *, ...) __attribute__((format(__NSString__, 1, 2)));
extern void CFStringCreateWithFormat3(CFStringRef, ...) __attribute__((format(__NSString__, 1, 2)));
extern void printf2(NSString *format, ...) __attribute__((format(printf, 1, 2)));
extern NSString *CStringToNSString(const char *) __attribute__((format_arg(1)));
void NSLog3(const char *fmt, ...) {
NSString *const nsFmt = CStringToNSString(fmt);
va_list ap;
va_start(ap, fmt);
NSLogv(nsFmt, ap);
va_end(ap);
}
void rdar_7068334(void) {
long long test = 500;
printf("%i ",test); NSLog(@"%i ",test); CFStringCreateWithFormat(CFSTR("%i"),test); }
void rdar_7697748(void) {
NSLog(@"%@!"); }
@protocol Foo;
void test_p_conversion_with_objc_pointer(id x, id<Foo> y) {
printf("%p", x); printf("%p", y); }
extern void MyNSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
extern void MyCFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(__CFString__, 1, 2)));
void check_mylog(void) {
MyNSLog(@"%@"); MyCFStringCreateWithFormat(CFSTR("%@")); }
@interface Foo
+ (id)fooWithFormat:(NSString *)fmt, ... __attribute__((format(__NSString__, 1, 2)));
+ (id)fooWithCStringFormat:(const char *)format, ... __attribute__((format(__printf__, 1, 2)));
@end
void check_method(void) {
[Foo fooWithFormat:@"%@"]; [Foo fooWithCStringFormat:"%@"]; }
void rdar10743758(id x) {
NSLog(@"%@ %@", x, (BOOL) 1); }
NSString *test_literal_propagation(void) {
const char * const s1 = "constant string %s"; printf(s1); const char * const s5 = "constant string %s"; const char * const s2 = s5;
printf(s2);
const char * const s3 = (const char *)0;
printf(s3);
NSString * const ns1 = @"constant string %s"; NSLog(ns1); NSString * const ns5 = @"constant string %s"; NSString * const ns2 = ns5;
NSLog(ns2); NSString * ns3 = ns1;
NSLog(ns3);
NSString * const ns6 = @"split" " string " @"%s"; NSLog(ns6); }
#include "format-strings-system.h"
#define MyNSLocalizedString(key) GetLocalizedString(key)
#define MyNSAssert(fmt, arg) NSLog(fmt, arg, 0, 0)
void check_NSLocalizedString(void) {
[Foo fooWithFormat:NSLocalizedString(@"format"), @"arg"]; [Foo fooWithFormat:MyNSLocalizedString(@"format"), @"arg"]; }
void check_NSAssert(void) {
NSAssert(@"Hello %@", @"World"); MyNSAssert(@"Hello %@", @"World"); }
typedef __WCHAR_TYPE__ wchar_t;
void test_percent_S(void) {
const unsigned short data[] = { 'a', 'b', 0 };
const unsigned short* ptr = data;
NSLog(@"%S", ptr);
const wchar_t* wchar_ptr = L"ab";
NSLog(@"%S", wchar_ptr); }
void test_percent_ls(void) {
const unsigned short data[] = { 'a', 'b', 0 };
const unsigned short* ptr = data;
NSLog(@"%ls", ptr);
const wchar_t* wchar_ptr = L"ab";
NSLog(@"%ls", wchar_ptr); }
void test_percent_C(void) {
const unsigned short data = 'a';
NSLog(@"%C", data);
const wchar_t wchar_data = L'a';
NSLog(@"%C", wchar_data); }
void test_toll_free_bridging(CFStringRef x, id y) {
NSLog(@"%@", x); CFStringCreateWithFormat(CFSTR("%@"), x);
NSLog(@"%@", y); CFStringCreateWithFormat(CFSTR("%@"), y); }
@interface Bar
+ (void)log:(NSString *)fmt, ...;
+ (void)log2:(NSString *)fmt, ... __attribute__((format(NSString, 1, 2)));
@end
@implementation Bar
+ (void)log:(NSString *)fmt, ... {
va_list ap;
va_start(ap,fmt);
NSLogv(fmt, ap); va_end(ap);
}
+ (void)log2:(NSString *)fmt, ... {
va_list ap;
va_start(ap,fmt);
NSLogv(fmt, ap); va_end(ap);
}
@end
void rdar11049844_aux(void);
int rdar11049844(void) {
typedef void (^MyBlock)(void);
MyBlock x = ^void(void) { rdar11049844_aux(); };
printf("%p", x); }
void test_nonBuiltinCFStrings(void) {
CFStringCreateWithFormat(__CFStringMakeConstantString("%@"), 1); }
@interface NSDictionary : NSObject
- (id)objectForKeyedSubscript:(id)key;
@end
void testInvalidFormatArgument(NSDictionary *dict) {
NSLog(@"no specifiers", dict[CFSTR("abc")]); NSLog(@"%@", dict[CFSTR("abc")]); NSLog(@"%@ %@", dict[CFSTR("abc")]);
[Foo fooWithFormat:@"no specifiers", dict[CFSTR("abc")]]; [Foo fooWithFormat:@"%@", dict[CFSTR("abc")]]; [Foo fooWithFormat:@"%@ %@", dict[CFSTR("abc")]]; }
void testByValueObjectInFormat(Foo *obj) {
printf("%d %d %d", 1L, *obj, 1L); printf("%!", *obj); printf(0, *obj);
[Bar log2:@"%d", *obj]; }
void testTypeOf(NSInteger dW, NSInteger dH) {
NSLog(@"dW %d dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; }),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); }
void testUnicode(void) {
NSLog(@"%C", 0x2022); NSLog(@"%C", 0x202200); }
void testObjCModifierFlags(void) {
NSLog(@"%[]@", @"Foo"); NSLog(@"%[", @"Foo"); NSLog(@"%[tt", @"Foo"); NSLog(@"%[tt]@", @"Foo"); NSLog(@"%[tt]@ %s", @"Foo", "hello"); NSLog(@"%s %[tt]@", "hello", @"Foo"); NSLog(@"%[blark]@", @"Foo"); NSLog(@"%2$[tt]@ %1$[tt]@", @"Foo", @"Bar"); NSLog(@"%2$[tt]@ %1$[tt]s", @"Foo", @"Bar"); }
@interface RD23622446_Tester: NSObject
+ (void)stringWithFormat:(const char *)format, ... __attribute__((format(__printf__, 1, 2)));
@end
@implementation RD23622446_Tester
__attribute__ ((format_arg(1)))
const char *rd23622446(const char *format) {
return format;
}
+ (void)stringWithFormat:(const char *)format, ... {
return;
}
- (const char *)test:(const char *)format __attribute__ ((format_arg(1))) {
return format;
}
- (NSString *)str:(NSString *)format __attribute__ ((format_arg(1))) {
return format;
}
- (void)foo {
[RD23622446_Tester stringWithFormat:rd23622446("%u"), 1, 2]; [RD23622446_Tester stringWithFormat:[self test: "%u"], 1, 2]; [RD23622446_Tester stringWithFormat:[self test: "%s %s"], "name"]; NSLog([self str: @"%@ %@"], @"name"); [RD23622446_Tester stringWithFormat:rd23622446("%d"), 1]; [RD23622446_Tester stringWithFormat:[self test: "%d %d"], 1, 2]; NSLog([self str: @"%@"], @"string"); }
@end
@interface NSBundle : NSObject
- (NSString *)localizedStringForKey:(NSString *)key
value:(nullable NSString *)value
table:(nullable NSString *)tableName
__attribute__((format_arg(1)));
- (NSString *)someRandomMethod:(NSString *)key
value:(nullable NSString *)value
table:(nullable NSString *)tableName
__attribute__((format_arg(1)));
- (NSAttributedString *)someMethod2:(NSString *)key
__attribute__((format_arg(1)));
@end
void useLocalizedStringForKey(NSBundle *bndl) {
[NSString stringWithFormat:
[bndl localizedStringForKey:@"%d" value:0
table:0]];
[NSString stringWithFormat: [bndl localizedStringForKey:@"flerp" value:0 table:0], 43, @"flarp"];
[NSString stringWithFormat:
[bndl localizedStringForKey:@"%f"
value:0
table:0], 42];
[NSString stringWithFormat:
[bndl someRandomMethod:@"%f"
value:0
table:0], 42];
[NSString stringWithFormat:
[bndl someRandomMethod:@"flerp"
value:0
table:0], 42];
[NSAttributedString stringWithFormat:
[bndl someMethod2: @"test"], 5]; [NSAttributedString stringWithFormat:
[bndl someMethod2: @"%f"], 42]; }