[clang] [clang][Sema] Stop format size estimator upon %p to adapt to linux kernel's extension (PR #65969)

Takuya Shimizu via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 12 05:37:57 PDT 2023


================
@@ -851,6 +851,50 @@ class ScanfDiagnosticFormatHandler
   }
 };
 
+/// `I` points to the next character of `%p` format.
+/// This functon checks if the subsequent character can be linux kernel's
+/// extnded format specifier
+static inline constexpr bool canBeLinuxFormatExtension(const char *I,
+                                                       const char *E) {
+  assert(I < E && "format string not yet exhausted");
+  // Kernel Document: https://docs.kernel.org/core-api/printk-formats.html
+  switch (*I) {
----------------
hazohelet wrote:

These switch cases correspond to https://github.com/torvalds/linux/blob/0bb80ecc33a8fb5a682236443c1e740d5c917d1d/lib/vsprintf.c#L2406-L2412
Note that kernel extension `%pA` is for Rust and thus excluded here.
ref: https://docs.kernel.org/core-api/printk-formats.html

https://github.com/llvm/llvm-project/pull/65969


More information about the cfe-commits mailing list