[cfe-dev] Additional annotations for static analysis (Objective C designated initializers)

Louis Gerbarg lgerbarg at gmail.com
Wed Oct 29 22:27:05 PDT 2008


It has been a while (4 years?) since I have submitted any code to
LLVM, but I like to keep up with you guys. I am constantly using
checker, and it has occurred to me there were some very valuable
checks that could be done with a small amount of additional source
code annotation. GCC already has limited support for some things, like
_attribute__((sentinel(0,1))), but the combination of clang and the
analysis framework could allow for much more interesting things. For
example, if we added an __attribute__((designated_initializer)) we
could mark the designated initializer of an objective C class in its
header in order to make sure subclasses flow through the initializers
properly.

Now, normally before I do any real work I like to get people's
opinions, but clang is such a pleasure to work with I really have no
reason not to show up to the table with something. Attached is a small
patch to clang that adds the designated_initializer attribute, extends
the ObjCInterfaceDecl to know about designated initializers, and
implements a error if a class declares more than one designated
initializer. I am also attaching quick test case I wrote for the
error, though I have not actually managed to rig it up in the test
harness yet.

Assuming people are okay with this, it seems like it should be pretty
trivial to extend checker so that it actually can evaluate the rules
for designated initializers
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_13_section_3.html>.
While it does require annotating headers, marking one method per class
in my framework headers does not seem prohibitive, and to me this
feels like the sort of check that would like find lots and lots of
errors if the system headers were annotated;

 Anyway, just thought I would check and see what people thought.

Louis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-designated_initializer.patch
Type: application/octet-stream
Size: 5756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081030/1506afe3/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: designated-initializer-annotation.m
Type: application/octet-stream
Size: 414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081030/1506afe3/attachment-0001.obj>


More information about the cfe-dev mailing list