aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaObjC
diff options
context:
space:
mode:
authorJared Grubb <jaredgrubb@gmail.com>2024-04-29 09:16:00 -0700
committerGitHub <noreply@github.com>2024-04-29 17:16:00 +0100
commite3750fb65acf0f7447f6a49a0ba5d3197f4d9766 (patch)
tree5529d52427c12bb77959947876e8c8c51721303c /clang/test/SemaObjC
parent2903df02fb3c057849aaa796a91289b01950a5f0 (diff)
downloadllvm-e3750fb65acf0f7447f6a49a0ba5d3197f4d9766.zip
llvm-e3750fb65acf0f7447f6a49a0ba5d3197f4d9766.tar.gz
llvm-e3750fb65acf0f7447f6a49a0ba5d3197f4d9766.tar.bz2
[Clang] Add diagnostic about "%P" specifier with Objective-C pointers (#89977)
A Darwin extension '%P' combined with an Objective-C pointer seems to always be a bug. '%P' will dump bytes at the pointed-to address (in contrast to '%p' which dumps the pointer itself). This extension is only allowed in "OS Log" contexts and is intended to be used like `%{uuid_t}.*16P` or `%{timeval}.*P`. If an ObjC pointer is used, then the internal runtime structure (aka, the is-a pointer and other runtime metadata) will be dumped, which (IMO) is never the expectation. A simple diagnostic can help flag these scenarios. Resolves https://github.com/llvm/llvm-project/issues/89968 Co-authored-by: Jared Grubb <jgrubb@apple.com>
Diffstat (limited to 'clang/test/SemaObjC')
-rw-r--r--clang/test/SemaObjC/format-strings-oslog.m5
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/test/SemaObjC/format-strings-oslog.m b/clang/test/SemaObjC/format-strings-oslog.m
index 20fec93..af5aef3 100644
--- a/clang/test/SemaObjC/format-strings-oslog.m
+++ b/clang/test/SemaObjC/format-strings-oslog.m
@@ -44,15 +44,18 @@ void test_os_log_format(const char *pc, int i, void *p, void *buf) {
}
// Test os_log_format primitive with ObjC string literal format argument.
-void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss) {
+void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss, id obj) {
__builtin_os_log_format(buf, @"");
__builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}}
__builtin_os_log_format(buf, @"%d", i);
+
__builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}
__builtin_os_log_format(buf, @"%.10P", p);
__builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
__builtin_os_log_format(buf, @"%.*P", i, p);
__builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
+ __builtin_os_log_format(buf, @"%.8P", nss); // expected-warning {{using '%P' format specifier with an Objective-C pointer results in dumping runtime object structure, not object value}}
+ __builtin_os_log_format(buf, @"%.*P", i, obj); // expected-warning {{using '%P' format specifier with an Objective-C pointer results in dumping runtime object structure, not object value}}
__builtin_os_log_format(buf, @"%{private}s", pc);
__builtin_os_log_format(buf, @"%@", nss);