Use CheckAssignmentConstraints for checking the cleanup attr function. Fixes PR3656.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65461 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def
index 24bca6a..e5e7f6e 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/include/clang/Basic/DiagnosticSemaKinds.def
@@ -412,8 +412,9 @@
DIAG(err_attribute_cleanup_func_must_take_one_arg, ERROR,
"'cleanup' function %0 must take 1 parameter")
DIAG(err_attribute_cleanup_func_arg_incompatible_type, ERROR,
- "'cleanup' function %0 parameter has type %1, expected type %2")
-
+ "'cleanup' function %0 parameter has type %1 which is incompatible with "
+ "type %2")
+
// Clang-Specific Attributes
DIAG(err_attribute_iboutlet, ERROR,
"'iboutlet' attribute can only be applied to instance variables or properties")
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index ce38edd..fb8b795 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -955,7 +955,7 @@
// 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) {
+ if (S.CheckAssignmentConstraints(Ty, ParamTy) != Sema::Compatible) {
S.Diag(Attr.getLoc(),
diag::err_attribute_cleanup_func_arg_incompatible_type) <<
Attr.getParameterName() << ParamTy << Ty;
diff --git a/test/Sema/attr-cleanup.c b/test/Sema/attr-cleanup.c
index e5dd3a2..d239c1a 100644
--- a/test/Sema/attr-cleanup.c
+++ b/test/Sema/attr-cleanup.c
@@ -29,5 +29,5 @@
void t2()
{
int v1 __attribute__((cleanup(c2))); // expected-error {{'cleanup' function 'c2' must take 1 parameter}}
- int v2 __attribute__((cleanup(c3))); // expected-error {{'cleanup' function 'c3' parameter has type 'struct s', expected type 'int *'}}
+ int v2 __attribute__((cleanup(c3))); // expected-error {{'cleanup' function 'c3' parameter has type 'struct s' which is incompatible with type 'int *'}}
}
diff --git a/test/SemaObjC/attr-cleanup.m b/test/SemaObjC/attr-cleanup.m
new file mode 100644
index 0000000..8490e6d
--- /dev/null
+++ b/test/SemaObjC/attr-cleanup.m
@@ -0,0 +1,10 @@
+// RUN: clang %s -verify -fsyntax-only
+
+@class NSString;
+
+void c1(id *a);
+
+void t1()
+{
+ NSString *s __attribute((cleanup(c1)));
+}