[all-commits] [llvm/llvm-project] 364817: [analyzer] Consider single-elem arrays as FAMs by ...
Balazs Benics via All-commits
all-commits at lists.llvm.org
Fri Nov 25 01:26:04 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 36481758390caa19d54bbab94d2f5e927fbec1c2
https://github.com/llvm/llvm-project/commit/36481758390caa19d54bbab94d2f5e927fbec1c2
Author: Balazs Benics <benicsbalazs at gmail.com>
Date: 2022-11-25 (Fri, 25 Nov 2022)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
M clang/test/Analysis/analyzer-config.c
M clang/test/Analysis/flexible-array-members.c
Log Message:
-----------
[analyzer] Consider single-elem arrays as FAMs by default
According to my measurement in https://reviews.llvm.org/D108230#3933232,
it seems like there is no drawback to enabling this analyzer-config by default.
Actually, enabling this by default would make it consistent with the
codegen of clang, which according to `-fstrict-flex-arrays`, assumes
by default that all trailing arrays could be FAMs, let them be of size
undefined, zero, one, or anything else.
Speaking of `-fstrict-flex-arrays`, in the next patch I'll deprecate
the analyzer-config FAM option in favor of that flag. That way, CSA will
always be in sync with what the codegen will think of FAMs.
So, if a new codebase sets `-fstrict-flex-arrays` to some value above 0,
CSA will also make sure that only arrays of the right size will be
considered as FAMs.
Reviewed By: xazax.hun
Differential Revision: https://reviews.llvm.org/D138657
Commit: 097ce7616527b8948b2a69d1300a44f552959a43
https://github.com/llvm/llvm-project/commit/097ce7616527b8948b2a69d1300a44f552959a43
Author: Balazs Benics <benicsbalazs at gmail.com>
Date: 2022-11-25 (Fri, 25 Nov 2022)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/DiagnosticDriverKinds.td
M clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
M clang/lib/Frontend/CompilerInvocation.cpp
M clang/lib/StaticAnalyzer/Core/MemRegion.cpp
M clang/test/Analysis/deprecated-flags-and-options.cpp
M clang/test/Analysis/flexible-array-members.c
Log Message:
-----------
[analyzer] Deprecate FAM analyzer-config, recommend -fstrict-flex-arrays instead
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 consdering 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
Reviewed By: xazax.hun
Differential Revision: https://reviews.llvm.org/D138659
Compare: https://github.com/llvm/llvm-project/compare/a89c9bafe67f...097ce7616527
More information about the All-commits
mailing list