On Aug 9, 2009, at 3:36 PM, Ryan Flynn wrote: > Author: pizza > Date: Sun Aug 9 17:36:29 2009 > New Revision: 78542 > > URL: http://llvm.org/viewvc/llvm-project?rev=78542&view=rev > Log: > warn, as gcc does, if __attribute__((malloc)) applied to function > returning non-pointer type
Thanks Ryan. If "d" is not a functiondecl, does it make sense to reject (with a warning) the attribute? -Chris > > Modified: > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/lib/Sema/SemaDeclAttr.cpp > cfe/trunk/test/Sema/attr-malloc.c > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=78542&r1=78541&r2=78542&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 9 > 17:36:29 2009 > @@ -605,6 +605,8 @@ > "'%0' attribute invalid on this declaration, requires typedef or > value">; > def warn_attribute_nonnull_no_pointers : Warning< > "'nonnull' attribute applied to function with no pointer > arguments">; > +def warn_attribute_malloc_pointer_only : Warning< > + "'malloc' attribute only applies to functions returning pointer > type">; > def warn_transparent_union_nonpointer : Warning< > "'transparent_union' attribute support incomplete; only supported > for " > "pointer unions">; > > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=78542&r1=78541&r2=78542&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Aug 9 17:36:29 2009 > @@ -437,6 +437,13 @@ > return; > } > > + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) { > + if (!FD->getResultType()->isPointerType()) { > + S.Diag(Attr.getLoc(), > diag::warn_attribute_malloc_pointer_only); > + return; > + } > + } > + > d->addAttr(::new (S.Context) MallocAttr()); > } > > > Modified: cfe/trunk/test/Sema/attr-malloc.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-malloc.c?rev=78542&r1=78541&r2=78542&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/test/Sema/attr-malloc.c (original) > +++ cfe/trunk/test/Sema/attr-malloc.c Sun Aug 9 17:36:29 2009 > @@ -5,6 +5,12 @@ > > int no_vars __attribute((malloc)); // expected-warning {{only > applies to function types}} > > +void returns_void (void) __attribute((malloc)); // expected- > warning {{functions returning pointer type}} > +int returns_int (void) __attribute((malloc)); // expected- > warning {{functions returning pointer type}} > +int * returns_intptr(void) __attribute((malloc)); > +typedef int * iptr; > +iptr returns_iptr (void) __attribute((malloc)); > + > __attribute((malloc)) > void * xalloc(unsigned n) { return malloc(n); } > // RUN: grep 'define noalias .* @xalloc(' %t && > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
