[PATCH] Make VLA size checker detect negative array sizes

Daniel Fahlgren daniel at fahlgren.se
Mon Aug 11 09:08:37 PDT 2014


Hi Jordan,

On Mon, 2014-06-16 at 13:01 -0700, Jordan Rose wrote:
> Getting back to this late. Would it be better to use constraints to check this?
> 
> if (!state->assume(/* size >= 0 */)) { /* error */ }

Sorry for the late reply. Vacation and life somehow got in the way of
coding.

Yes, that is be better. The old patch did not catch things like:

static void bar(int x)
{
  int vla[x];
}

void foo(int x) {
  if (x < 0)
    bar(x);
}

Attached is an updated version of the patch with the above test case.
Since this is my first real encounter with constraints I'm sure things
can be done in a better way. Feedback is welcome. :)

Best regards,
Daniel Fahlgren
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VLA.patch
Type: text/x-patch
Size: 4032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140811/ebe98c7d/attachment.bin>


More information about the cfe-commits mailing list