[PATCH] [StaticAnalyzer] New checker Sizeof on expression

Aaron Ballman aaron at aaronballman.com
Thu Jan 23 09:22:07 PST 2014


On Thu, Jan 23, 2014 at 12:18 PM, Anders Rönnholm
<Anders.Ronnholm at evidente.se> wrote:
> <<A few thoughts:
> <<
> <<Could this be generalized to fit _Alignof and _Generic (the controlling expression) as well? The behavior is the same for all three <<(they're unevaluated).
> <<
> I wonder if we could wait with this.

I don't think it should block this patch, though perhaps some of the
identifiers (and diagnostics) could be genericized in anticipation of
this functionality?

>
> <<Also, in terms of sizeof, if the expression modifies a VLA, the behavior is sadly well-defined (in C). Eg)
> <<
> <<size_t f(size_t n) {
> <<  /* n must be incremented */
> <<  size_t a = sizeof(int[++n]);
> <<  return n;
> <<}
>>>This will return n + 1 because it affects the size of the VLA. So we probably should not warn on that case.
> <<
> Good because this checker does not warn in this case.

Fantastic!

~Aaron




More information about the cfe-commits mailing list