Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 189850)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -2350,7 +2350,7 @@
 def err_attribute_cleanup_arg_not_found : Error<
   "'cleanup' argument %0 not found">;
 def err_attribute_cleanup_arg_not_function : Error<
-  "'cleanup' argument %0 is not a function">;
+  "'cleanup' argument %select{|%1 }0is not a function">;
 def err_attribute_cleanup_func_must_take_one_arg : Error<
   "'cleanup' function %0 must take 1 parameter">;
 def err_attribute_cleanup_func_arg_incompatible_type : Error<
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp	(revision 189851)
+++ lib/Sema/SemaDeclAttr.cpp	(working copy)
@@ -2987,43 +2987,33 @@
 }
 
 static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (!Attr.isArgIdent(0)) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
-      << Attr.getName() << 1;
-    return;
-  }
-  
   if (!checkAttributeNumArgs(S, Attr, 1))
     return;
 
   VarDecl *VD = dyn_cast<VarDecl>(D);
-
   if (!VD || !VD->hasLocalStorage()) {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "cleanup";
+    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
     return;
   }
 
-  IdentifierLoc *IL = Attr.getArgAsIdent(0);
-
-  // Look up the function
-  // FIXME: Lookup probably isn't looking in the right place
-  NamedDecl *CleanupDecl
-    = S.LookupSingleName(S.TUScope, IL->Ident, IL->Loc,
-                         Sema::LookupOrdinaryName);
-  if (!CleanupDecl) {
-    S.Diag(IL->Loc, diag::err_attribute_cleanup_arg_not_found) << IL->Ident;
+  Expr *E = Attr.getArgAsExpr(0);
+  SourceLocation Loc = E->getExprLoc();
+  DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
+  if (!DRE) {
+    S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
     return;
   }
 
-  FunctionDecl *FD = dyn_cast<FunctionDecl>(CleanupDecl);
+  FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
   if (!FD) {
-    S.Diag(IL->Loc, diag::err_attribute_cleanup_arg_not_function) << IL->Ident;
+    S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
+      << DRE->getNameInfo().getName();
     return;
   }
 
   if (FD->getNumParams() != 1) {
-    S.Diag(IL->Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
-      << IL->Ident;
+    S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
+      << DRE->getNameInfo().getName();
     return;
   }
 
@@ -3033,16 +3023,14 @@
   QualType ParamTy = FD->getParamDecl(0)->getType();
   if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
                                    ParamTy, Ty) != Sema::Compatible) {
-    S.Diag(IL->Loc, diag::err_attribute_cleanup_func_arg_incompatible_type) <<
-      IL->Ident << ParamTy << Ty;
+    S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
+      << DRE->getNameInfo().getName() << ParamTy << Ty;
     return;
   }
 
   D->addAttr(::new (S.Context)
              CleanupAttr(Attr.getRange(), S.Context, FD,
                          Attr.getAttributeSpellingListIndex()));
-  S.MarkFunctionReferenced(IL->Loc, FD);
-  S.DiagnoseUseOfDecl(FD, IL->Loc);
 }
 
 /// Handle __attribute__((format_arg((idx)))) attribute based on
Index: test/CodeGenCXX/attr-cleanup.cpp
===================================================================
--- test/CodeGenCXX/attr-cleanup.cpp	(revision 0)
+++ test/CodeGenCXX/attr-cleanup.cpp	(working copy)
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+namespace N {
+  void free(void *i) {}
+}
+
+int main(void) {
+  // CHECK: call void @_ZN1N4freeEPv(i8* %0)
+  void *fp __attribute__((cleanup(N::free)));
+  return 0;
+}
Index: test/Sema/attr-cleanup.c
===================================================================
--- test/Sema/attr-cleanup.c	(revision 189850)
+++ test/Sema/attr-cleanup.c	(working copy)
@@ -2,18 +2,18 @@
 
 void c1(int *a);
 
-extern int g1 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
-int g2 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
-static int g3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+extern int g1 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute ignored}}
+int g2 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute ignored}}
+static int g3 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute ignored}}
 
 void t1()
 {
     int v1 __attribute((cleanup)); // expected-error {{'cleanup' attribute takes one argument}}
     int v2 __attribute((cleanup(1, 2))); // expected-error {{'cleanup' attribute takes one argument}}
 
-    static int v3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+    static int v3 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute ignored}}
 
-    int v4 __attribute((cleanup(h))); // expected-error {{'cleanup' argument 'h' not found}}
+    int v4 __attribute((cleanup(h))); // expected-error {{use of undeclared identifier 'h'}}
 
     int v5 __attribute((cleanup(c1)));
     int v6 __attribute((cleanup(v3))); // expected-error {{'cleanup' argument 'v3' is not a function}}
@@ -42,3 +42,7 @@
 void t5() {
   int i __attribute__((cleanup(c5)));  // expected-warning {{'c5' is deprecated}}
 }
+
+void t6(void) {
+  int i __attribute__((cleanup((void *)0)));  // expected-error {{'cleanup' argument is not a function}}
+}
Index: test/SemaCXX/attr-cleanup.cpp
===================================================================
--- test/SemaCXX/attr-cleanup.cpp	(revision 0)
+++ test/SemaCXX/attr-cleanup.cpp	(working copy)
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+namespace N {
+  void c1(int *a) {}
+}
+
+void t1() {
+  int v1 __attribute__((cleanup(N::c1)));
+  int v2 __attribute__((cleanup(N::c2)));  // expected-error {{no member named 'c2' in namespace 'N'}}
+}
Index: utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- utils/TableGen/ClangAttrEmitter.cpp	(revision 189851)
+++ utils/TableGen/ClangAttrEmitter.cpp	(working copy)
@@ -1003,6 +1003,7 @@
           .Case("AlignedArgument", true)
           .Case("BoolArgument", true)
           .Case("DefaultIntArgument", true)
+          .Case("FunctionArgument", true)
           .Case("IntArgument", true)
           .Case("ExprArgument", true)
           .Case("StringArgument", true)
