]> granicus.if.org Git - clang/commit
[PATCH] Adding checker to detect excess padding in records
authorBen Craig <ben.craig@codeaurora.org>
Mon, 14 Dec 2015 21:38:59 +0000 (21:38 +0000)
committerBen Craig <ben.craig@codeaurora.org>
Mon, 14 Dec 2015 21:38:59 +0000 (21:38 +0000)
commit1b26d93e5d7d6b9dbaed1900575923f7dc588399
treeb9a895f364c373d71ecce1adb32d7273ee56fedf
parent73510e6e20e954b8dae736fdde4f4a692df8b7e3
[PATCH] Adding checker to detect excess padding in records

The intent of this checker is to generate a report for any class / structure
that could reduce its padding by reordering the fields.  This results in a very
noisy checker.  To reduce the noise, this checker will currently only warn when
the number of bytes over "optimal" is more than 24.  This value is configurable
with -analyzer-config performance.Padding:AllowedPad=N.  Small values of
AllowedPad have the potential to generate hundreds of reports, and gigabytes
of HTML reports.

The checker searches for padding violations in two main ways.  First, it goes
record by record.  A report is generated if the fields could be reordered in a
way that reduces the padding by more than AllowedPad bytes.  Second, the
checker will generate a report if an array will cause more than AllowedPad
padding bytes to be generated.

The record checker currently skips many ABI specific cases.  Classes with base
classes are skipped because base class tail padding is ABI specific.  Bitfields
are just plain hard, and duplicating that code seems like a bad idea.  VLAs are
both uncommon and non-trivial to fix.

The array checker isn't very thorough right now.  It only checks to see if the
element type's fields could be reordered, and it doesn't recursively check to
see if any of the fields' fields could be reordered.  At some point in the
future, it would be nice if "arrays" could also look at array new usages and
malloc patterns that appear to be creating arrays.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255545 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/Checkers.td
lib/StaticAnalyzer/Checkers/PaddingChecker.cpp [new file with mode: 0644]
test/Analysis/padding_c.c [new file with mode: 0644]
test/Analysis/padding_cpp.cpp [new file with mode: 0644]
test/Analysis/padding_message.cpp [new file with mode: 0644]