[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 26 08:35:36 PDT 2024
NagyDonat wrote:
> These results look correct according to the checker, but I am not sure if such results are useful or really invalid: https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_pointersub1&is-unique=on&diff-type=New&checker-name=alpha.core.PointerSub In these cases the address difference of an (array) member of a struct and start of the struct is taken. According to the checker rules, taking difference of addresses of any variables or member variables is invalid.
This trickery basically reimplements `offsetof()` (or something very similar to it), and as it is in the stable `vim` repo I assume that it's accepted by practically all compilers; but it clearly violates the language standard so I think it's good that the checker reports it. (Perhaps this trick would've been acceptable thirty years ago, but now we have standard `offsetof()` that usually expands to `__builtin_offsetof()` so developers who try to use homemade alternatives deserve a warning.)
https://github.com/llvm/llvm-project/pull/96501
More information about the cfe-commits
mailing list