r193055 - Fix crash in cleanup attr handling

Alp Toker alp at nuanti.com
Sun Oct 20 11:48:56 PDT 2013


Author: alp
Date: Sun Oct 20 13:48:56 2013
New Revision: 193055

URL: http://llvm.org/viewvc/llvm-project?rev=193055&view=rev
Log:
Fix crash in cleanup attr handling

ResolveSingleFunctionTemplateSpecialization() returns 0 and doesn't emit diags
unless the expression has template-ids, so we must null check the result.

Also add a better diag noting which overloads are causing the problem.

Reviewed by Aaron Ballman.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/attr-cleanup.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=193055&r1=193054&r2=193055&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Oct 20 13:48:56 2013
@@ -2365,7 +2365,7 @@ def warn_cleanup_ext : Warning<
   "than a simple identifier">, 
   InGroup<GccCompat>;
 def err_attribute_cleanup_arg_not_function : Error<
-  "'cleanup' argument %select{|%1 }0is not a function">;
+  "'cleanup' argument %select{|%1 |%1 }0is not a %select{||single }0function">;
 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<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=193055&r1=193054&r2=193055&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Oct 20 13:48:56 2013
@@ -2899,10 +2899,15 @@ static void handleCleanupAttr(Sema &S, D
   } else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
     if (ULE->hasExplicitTemplateArgs())
       S.Diag(Loc, diag::warn_cleanup_ext);
-
-    // This will diagnose the case where the function cannot be found.
     FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true);
     NI = ULE->getNameInfo();
+    if (!FD) {
+      S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
+        << NI.getName();
+      if (ULE->getType() == S.Context.OverloadTy)
+        S.NoteAllOverloadCandidates(ULE);
+      return;
+    }
   } else {
     S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
     return;

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=193055&r1=193054&r2=193055&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Oct 20 13:48:56 2013
@@ -9672,6 +9672,9 @@ Sema::ResolveAddressOfOverloadedFunction
 /// template, where that template-id refers to a single template whose template
 /// arguments are either provided by the template-id or have defaults,
 /// as described in C++0x [temp.arg.explicit]p3.
+///
+/// If no template-ids are found, no diagnostics are emitted and NULL is
+/// returned.
 FunctionDecl *
 Sema::ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 
                                                   bool Complain,

Modified: cfe/trunk/test/SemaCXX/attr-cleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cleanup.cpp?rev=193055&r1=193054&r2=193055&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-cleanup.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-cleanup.cpp Sun Oct 20 13:48:56 2013
@@ -19,3 +19,11 @@ class D : public C {
     int v1 __attribute__((cleanup(c2)));  // expected-error {{'c2' is a private member of 'C'}}
   }
 };
+
+namespace E {
+  void c3(int *a) {} // expected-note {{candidate function}}
+  void c3() {}       // expected-note {{candidate function}}
+  void t3() {
+    int v1 __attribute__((cleanup(c3))); // expected-error {{'c3' is not a single function}}
+  }
+}





More information about the cfe-commits mailing list