You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Add diagnostic about "%P" specifier with Objective-C pointers (llvm#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.
Resolvesllvm#89968
Co-authored-by: Jared Grubb <[email protected]>
Copy file name to clipboardExpand all lines: clang/test/SemaObjC/format-strings-oslog.m
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -44,15 +44,18 @@ void test_os_log_format(const char *pc, int i, void *p, void *buf) {
44
44
}
45
45
46
46
// Test os_log_format primitive with ObjC string literal format argument.
47
-
voidtest_objc(constchar *pc, int i, void *p, void *buf, NSString *nss) {
47
+
voidtest_objc(constchar *pc, int i, void *p, void *buf, NSString *nss, id obj) {
48
48
__builtin_os_log_format(buf, @"");
49
49
__builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}}
50
50
__builtin_os_log_format(buf, @"%d", i);
51
+
51
52
__builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}
52
53
__builtin_os_log_format(buf, @"%.10P", p);
53
54
__builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
54
55
__builtin_os_log_format(buf, @"%.*P", i, p);
55
56
__builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
57
+
__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}}
58
+
__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}}
0 commit comments