[PATCH] D138659: [analyzer] Deprecate FAM analyzer-config, recommend -fstrict-flex-arrays instead

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 24 04:46:27 PST 2022


steakhal created this revision.
steakhal added reviewers: NoQ, xazax.hun.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

By default, clang assumes that all trailing array objects could be a
FAM. So, an array of undefined size, size 0, size 1, or even size 42 is
considered as FAMs for optimizations at least.

One needs to override the default behavior by supplying the
`-fstrict-flex-arrays=<N>` flag, with `N > 0` value to reduce the set of
FAM candidates. Value `3` is the most restrictive and `0` is the most
permissive on this scale.

0: all trailing arrays are FAMs
1: only incomplete, zero and one-element arrays are FAMs
2: only incomplete, zero-element arrays are FAMs
3: only incomplete arrays are FAMs

If the user is happy with considering single-element arrays as FAMs, they
just need to remove the
`consider-single-element-arrays-as-flexible-array-members` from the
command line.
Otherwise, if they don't want to recognize such cases as FAMs, they
should specify `-fstrict-flex-arrays` anyway, which will be picked up by
CSA.

Any use of the deprecated analyzer-config value will trigger a warning
explaining what to use instead.
The `-analyzer-config-help` is updated accordingly.

Depends on D138657 <https://reviews.llvm.org/D138657>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138659

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/deprecated-flags-and-options.cpp
  clang/test/Analysis/flexible-array-members.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138659.477747.patch
Type: text/x-patch
Size: 9511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221124/7923f028/attachment.bin>


More information about the cfe-commits mailing list