This is an archive of the discontinued LLVM Phabricator instance.

[Analyzer][VLASize] Support multi-dimensional arrays.
ClosedPublic

Authored by balazske on Apr 2 2020, 7:01 AM.

Details

Summary

Check the size constraints for every (variable) dimension of the array.
Try to compute array size by multiplying size for every dimension.

Diff Detail

Event Timeline

balazske created this revision.Apr 2 2020, 7:01 AM

It would be great to see a test about properly setting the arrays extent. Otherwise LGTM.

clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
61

Hmm, why would we? The size is most probably unknown to us.

161–179

Ahaa, so if we have a vla[x][y][a][b] variable, VLALast would be vla[x], which allows you to get the actual element type. Could you explain that (maybe even with a small example like this) in the code?

200–202

How about

We were not able to determine extent of the array, return with the original state.
balazske updated this revision to Diff 255388.Apr 6 2020, 9:55 AM

Added comments and test for extent.

Szelethus accepted this revision.Apr 8 2020, 6:53 AM

LGTM, thanks! I'm not terribly knowledgable about VLAs, if someone else would gave a green light it would be even better.

This revision is now accepted and ready to land.Apr 8 2020, 6:53 AM
martong accepted this revision.Apr 8 2020, 8:15 AM

LGTM, nice work!

clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
163

I'd mention that we collect the sizes into SizeExpr. And perhaps that is not the best name in this sense, maybe VarLenSizeExprs would be more expressive.

clang/test/Analysis/vla.c
110

Great to have these tests.

balazske updated this revision to Diff 256307.Apr 9 2020, 7:47 AM
balazske marked 3 inline comments as done.

Small renamings and reformatting.

This revision was automatically updated to reflect the committed changes.