[PATCH] Fix crash in cleanup attr handling
Alp Toker
alp at nuanti.com
Sat Oct 19 23:19:14 PDT 2013
Reduction:
void c3(int *a) {
void c3() {}
void t3() {
int v1 __attribute__((cleanup(c3)));
}
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.
--
http://www.nuanti.com
the browser experts
-------------- next part --------------
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index d8fef68..a02c072 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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<
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 3eabf87..d38d619 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -2899,10 +2899,14 @@ static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
} 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();
+ S.NoteAllOverloadCandidates(ULE);
+ return;
+ }
} else {
S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
return;
diff --git a/test/SemaCXX/attr-cleanup.cpp b/test/SemaCXX/attr-cleanup.cpp
index b6c5853..764df99 100644
--- a/test/SemaCXX/attr-cleanup.cpp
+++ b/test/SemaCXX/attr-cleanup.cpp
@@ -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