Some of the checks performed by Sparse require annotating the source code using the __attribute__ GCC extension, or the Sparse-specific __context__ specifier.4 Sparse defines the following list of attributes:
When an API is defined with a macro, the specifier __attribute__((context(...))) can be replaced by __context__(...).
The Linux kernel defines the following short forms as pre-processor macros in files linux/compiler.h and linux/types.h (when building without the __CHECKER__ flag, all these annotations are removed from the code):
The types __le32 and __be32 represent 32-bit integer types with different endianness. However, the C language does not allow to specify that variables of these types should not be mixed. The bitwise attribute is used to mark these types as restricted, so Sparse will give a warning if variables of these types or other integer variables are mixed:
To mark valid conversions between restricted types, a casting with the force attribute is used to avoid Sparse giving a warning.
Yoann Padioleau; René Rydhof Hansen; Julia L. Lawall; Gilles Muller (2006). Semantic patches for documenting and automating collateral evolutions in Linux device drivers. Proceedings of the 3rd workshop on Programming languages and operating systems: linguistic support for modern operating systems. CiteSeerX 10.1.1.122.7080. doi:10.1145/1215995.1216005. ISBN 1-59593-577-0. The Linux community has recently begun using various tools to better analyze C code. Sparse is a library that, like a compiler front end, provides convenient access to the abstract syntax tree and typing information of a C program. 1-59593-577-0 ↩
Christopher Li (2009-10-16). "Sparse 0.4.2 released". linux-sparse (Mailing list). Retrieved 2010-11-06. https://marc.info/?l=linux-sparse&m=125570805231414&w=2 ↩
change Sparse's maintainer, retrieved December 10, 2018 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/MAINTAINERS?id=4e962ff6e34f44c400c548da0c1e2393053a691e ↩
"Attribute Syntax — Using the GNU Compiler Collection (GCC)". Free Software Foundation. Retrieved 2010-11-13. https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html ↩