[PATCH] D14779: Adding checker to detect excess padding in records
Ben Craig via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 18 08:43:04 PST 2015
bcraig created this revision.
bcraig added reviewers: zaks.anna, jordan_rose, xazax.hun.
bcraig added a subscriber: cfe-commits.
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 8. This value is configurable with -analyzer-config performance.Padding:AllowedPad=N. Even with the default of 8, this checker is too noisy to justify turning on by default. Clang+LLVM has hundreds of violations. A large C codebase was capable of generating more than 600 GB of HTML reports with AllowedPad=0.
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.
http://reviews.llvm.org/D14779
Files:
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/Checkers.td
lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
test/Analysis/padding_c.c
test/Analysis/padding_cpp.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14779.40518.patch
Type: text/x-patch
Size: 25334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151118/7f3f7a56/attachment-0001.bin>
More information about the cfe-commits
mailing list