[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 01:56:54 PDT 2024


NagyDonat wrote:

> The warning message may be still misleading if the LHS or RHS "arrays" are non-array variables.

I think that the warning message is OK: "Subtraction of two pointers that do not point into the same array is undefined behavior." -- this also covers the case when one or both of the pointers do not point to arrays. (It doesn't mention the corner case that it's also valid to subtract two identical pointers that point to a non-array value, but that's completely irrelevant in practice, so wouldn't be a helpful suggestion.)

> (or detect if `offsetof` can be used and include it in the message)?

I think that would be a waste of time, because it's very rare that a project manually reimplements `offsetof` -- I think it only appears in `vim` becasue it's a very old codebase. (Also developers who play with this kind of low-level trickery should be familiar with the standard and understand what's the problem.)


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


More information about the cfe-commits mailing list