[analyzer] Ignore single element arrays in getStaticSize() conditionally
authorBalazs Benics <balazs.benics@sigmatechnology.se>
Sat, 4 Sep 2021 08:19:57 +0000 (10:19 +0200)
committerBalazs Benics <balazs.benics@sigmatechnology.se>
Sat, 4 Sep 2021 08:19:57 +0000 (10:19 +0200)
commit91c07eb8ee6ea2d48158dce123bac7b7c30eb294
treea729e8dddafac48c15620eec3eabfbafaf9866fa
parent8f77dc459e31aad6daab89a124fa92067916274c
[analyzer] Ignore single element arrays in getStaticSize() conditionally

Quoting https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html:
> In the absence of the zero-length array extension, in ISO C90 the contents
> array in the example above would typically be declared to have a single
> element.

We should not assume that the size of the //flexible array member// field has
a single element, because in some cases they use it as a fallback for not
having the //zero-length array// language extension.
In this case, the analyzer should return `Unknown` as the extent of the field
instead.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D108230
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/flexible-array-members.c