[RFC] Starting support for SAL

I am starting to add support for Microsoft's source annotations so
that they can be used in the static analyzer. Before I go too far
into the implementation, I am wondering whether I'm approaching the
problem properly.

SAL has two separate implementations, depending on the compiler.
Older versions of MSVC use __declspec to implement the annotations,
and newer versions of MSVC use Microsoft's basically undocumented
attribute syntax. Initially, I am only implementing support for the
__declspec syntax, but would eventually like to support the attribute
syntax as well. The __declspec syntax relies on ordering of the
annotations. For instance, __declspec( "SAL_pre" ) __declspec(
"SAL_notnull" ) is not the same as __declspec( "SAL_notnull" )
__declspec( "SAL_pre" ).

I've created separate attributes for each of the SAL notations, and I
parse them in ParseMicrosoftDeclSpec. Some of the notations are
simple declspecs, and others have parameters to parse. Currently, I
am only parsing the simple ones, but I intend to parse the
parameterized ones and store the parameter information on the
attribute objects. All of the SAL declspecs are string literals.

I've attached an early stage patch, and am looking for feedback on
whether I am going about this properly, or if there is a better way.



SAL.diff (16.3 KB)

Hi Aaron,

I did a brief search for patents on “source code annotation language” and came up with this one, which seems to be patenting SAL annotations. (In particular, they talk about pre and post, writableTo, checkReturn… )

Looks like this patch might infringe on the patent and if so it should not be committed; see the LLVM developer policy:

Thanks for the initiative, it would be a great addition!

Well phooey! :wink: Thanks for finding that patent though, I'll suspend
working on this patch and focus elsewhere.