diff options
author | Félix Cloutier <fcloutier@apple.com> | 2022-05-12 11:09:06 -0700 |
---|---|---|
committer | Félix Cloutier <fcloutier@apple.com> | 2022-05-12 11:12:38 -0700 |
commit | 91ed7e19418181ae385c2626cedd3b08b6ba43a6 (patch) | |
tree | 488c77940d434f76ce2bfc8a816abfaa8907da45 /clang/test/SemaObjC | |
parent | ebdb9d635a077274e38baa8584f5b0e631b4b1d3 (diff) | |
download | llvm-91ed7e19418181ae385c2626cedd3b08b6ba43a6.zip llvm-91ed7e19418181ae385c2626cedd3b08b6ba43a6.tar.gz llvm-91ed7e19418181ae385c2626cedd3b08b6ba43a6.tar.bz2 |
[clang] Allow all string types for all attribute(format) styles
This allows using any recognized kind of string for any
__attribute__((format)) archetype. Before this change, for instance,
the printf archetype would only accept char pointer types and the
NSString archetype would only accept NSString pointers. This is
more restrictive than necessary as there exist functions to
convert between string types that can be annotated with
__attribute__((format_arg)) to transfer format information.
Reviewed By: ahatanak
Differential Revision: https://reviews.llvm.org/D125254
rdar://89060618
Diffstat (limited to 'clang/test/SemaObjC')
-rw-r--r-- | clang/test/SemaObjC/format-strings-objc.m | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/test/SemaObjC/format-strings-objc.m b/clang/test/SemaObjC/format-strings-objc.m index 6850ebf..71f22c0 100644 --- a/clang/test/SemaObjC/format-strings-objc.m +++ b/clang/test/SemaObjC/format-strings-objc.m @@ -60,8 +60,23 @@ void check_nslog(unsigned k) { } // Check type validation -extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-error {{format argument not an NSString}} -extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2))); // expected-error {{format argument not a CFString}} +extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-error {{format argument not a string type}} +extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2))); // expected-error {{format argument not a string type}} + +// Check interoperability of strings +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); +} // <rdar://problem/7068334> - Catch use of long long with int arguments. void rdar_7068334(void) { |