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

Ted Kremenek kremenek at apple.com
Wed Nov 5 17:28:11 PST 2008


On Nov 1, 2008, at 10:47 PM, Louis Gerbarg wrote:

>  no one had much in
> the way of implementation thoughts, I will take that either to mean my
> code is perfect, or more likely most of the people who can critique
> the code are busy trying to push out the next LLVM release ;-)

Here's some code review!  First, designated_initializer_attribute.patch:

+static void HandleDesignatedInitializerAttr(Decl *d, const  
AttributeList &Attr, Sema &S) {
+  // check the attribute arguments.
+  if (Attr.getNumArgs() != 0) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
+           std::string("0"));
+    return;
+  }
+
+  d->addAttr(new DesignatedInitializerAttr());
+}
+

This looks great, but I think designated initializers attributes  
should only apply to Objective-C method declarations  
(ObjCMethodDecl).  There should be a check in  
HandleDesignatedInitializerAttr to handle this case, e.g.:

if (!isa<ObjCMethodDecl>(d)) {
   S.Diag(...);
   return;
}

Otherwise everything else in that patch looks great.  I would also  
like a comment in the source code for HandleDesignatedInitializer that  
has a url that refers to the documentation of what a designated  
initializer is.  Copy-and-pasting from your email seems appropriate.



More information about the cfe-dev mailing list