On 06/28/2016 08:40 AM, Aldy Hernandez wrote:
Hi.

In addressing the issues that were brought up I ran into bounded allocas
that are bounded by an unknown size.  Should we warn on these?:

       if (n < SOME_GLOBAL)
         alloca(n)

In my WIP I am warning with:

     x.c:6:5: warning: alloca bound is unknown [-Walloca]

Though I wonder whether it's worth all the gymnastics I'm doing to
diagnose this correctly.

Thoughts?

The simple case above looks like a clear attempt to constrain
the size and so warning on it would probably be considered
a false positive.  At the same time, I suspect there will be
other, less straightforward, cases where the unknown bounds
might be incidental rather than the result of a deliberate
check for the size not exceeding some unknown threshold.  In
those, the warning might be useful.  The challenge is how to
tell the difference between the two sets of cases.

It might help to look at the else branch to see if there's
a call to malloc with the (unbounded) n. If there is, it would
be a good indicator that the bound is the result of a deliberate
test rather than incidental, and so the warning should be avoided.

Beyond that, if -Walloca had two levels of strictness, I would
be tempted to make this part of the stricter checker.  With just
one level, and beyond any clever heuristics, I think it comes
down to a judgment call, based on your experience with instances
of the warning you've seen in the real world code you've already
compiled with it.

Martin

Reply via email to