cleanup attribute argument checking

Hello,

There is currently this comment in SemaDeclAttr.cpp concerning the ‘cleanup’ attribute argument type checking:

// We’re currently more strict than GCC about what function types we accept.
// If this ever proves to be a problem it should be easy to fix.
QualType Ty = S.Context.getPointerType(VD->getType());
QualType ParamTy = FD->getParamDecl(0)->getType();
if (Ty != ParamTy) {
S.Diag(Attr.getLoc(),
diag::err_attribute_cleanup_func_arg_incompatible_type) <<
Attr.getParameterName() << ParamTy << Ty;
return;
}

It is a problem with objc as declaring a cleanup fonction that take an (id *) will force all variables that use this function to be strictly typed as ‘id’. (see bug #3656)

error: ‘cleanup’ function ‘$wb_scopeReleaseObject’ parameter has type ‘id *’, expected type ‘NSString **’

What could be done to workaround this issue ? It prevent compilation of file that gcc compile fine, and it prevent me to test clang with some objc projects :frowning:

This should probably be using Sema::CheckAssignmentConstraints or
something like that.

-Eli

Thanks. Look like the following condition will do the trick :slight_smile:

if (S.CheckAssignmentConstraints(Ty, ParamTy) != Sema::Compatible) {
  ...
}