[PATCH] D159138: [clang][Sema] Fix format size estimator's handling of %o, %x, %X with alternative form
Takuya Shimizu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 31 08:27:52 PDT 2023
hazohelet added a comment.
In D159138#4628858 <https://reviews.llvm.org/D159138#4628858>, @nickdesaulniers wrote:
> Mind adding tests for `%#X` and `%#o` as well, since you're changing the behavior of those, too?
>
> I think it would also be good to have explicit tests for `%o` and `%b` where the value being printed was and was not `0`. IIUC, we cannot diagnose those (unless a literal value is being printed)?
>
> (Thanks for finding that one of the kernel cases was a false positive!)
The current implementation only sees the format string and calculates the minimum possible length without taking into accout the actual value passed to it. So currently every case assumes that the value can be 0, even when a literal is passed.
Even if the printed expression is not literal, we can use something like `Expr::EvaluateAsRValue` to learn about the printed value.
As for the `%b`, it's C23 feature and `Wfortify-source` doesn't seem to support it yet (`%b` is considered a valid specifier, but does not increase `Size` here). I think `%b` tests should be added when we support it.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159138/new/
https://reviews.llvm.org/D159138
More information about the cfe-commits
mailing list