[cfe-commits] r95220 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/new-delete-predefined-decl.cpp test/SemaCXX/new-delete.cpp
Douglas Gregor
dgregor at apple.com
Wed Feb 3 07:45:55 PST 2010
On Feb 3, 2010, at 3:02 AM, Chandler Carruth wrote:
> Author: chandlerc
> Date: Wed Feb 3 05:02:14 2010
> New Revision: 95220
>
> URL: http://llvm.org/viewvc/llvm-project?rev=95220&view=rev
> Log:
> Teach the allocation function overload handling to deal with templates, and
> prevent a crash on templates when looking for an existing declaration of the
> predefined global operators. This fixes PR5918.
>
> Added an easy test case for the overload handling, but testing the crash is
> a bit trickier. Created a new test that can use multiple runs with a define to
> trigger which test case is used so we can test this type of issue.
>
> Added:
> cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp
> Modified:
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/new-delete.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=95220&r1=95219&r2=95220&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Feb 3 05:02:14 2010
> @@ -630,14 +630,19 @@
> Alloc != AllocEnd; ++Alloc) {
> // Even member operator new/delete are implicitly treated as
> // static, so don't use AddMemberCandidate.
> - if (FunctionDecl *Fn =
> - dyn_cast<FunctionDecl>((*Alloc)->getUnderlyingDecl())) {
> - AddOverloadCandidate(Fn, Alloc.getAccess(), Args, NumArgs, Candidates,
> - /*SuppressUserConversions=*/false);
> +
> + if (FunctionTemplateDecl *FnTemplate =
> + dyn_cast<FunctionTemplateDecl>((*Alloc)->getUnderlyingDecl())) {
> + AddTemplateOverloadCandidate(FnTemplate, Alloc.getAccess(),
> + /*ExplicitTemplateArgs=*/0, Args, NumArgs,
> + Candidates,
> + /*SuppressUserConversions=*/false);
> continue;
> - }
> -
> - // FIXME: Handle function templates
> + }
> +
> + FunctionDecl *Fn = cast<FunctionDecl>((*Alloc)->getUnderlyingDecl());
> + AddOverloadCandidate(Fn, Alloc.getAccess(), Args, NumArgs, Candidates,
> + /*SuppressUserConversions=*/false);
> }
>
> // Do the resolution.
> @@ -768,12 +773,16 @@
> DeclContext::lookup_iterator Alloc, AllocEnd;
> for (llvm::tie(Alloc, AllocEnd) = GlobalCtx->lookup(Name);
> Alloc != AllocEnd; ++Alloc) {
> - // FIXME: Do we need to check for default arguments here?
> - FunctionDecl *Func = cast<FunctionDecl>(*Alloc);
> - if (Func->getNumParams() == 1 &&
> + // Only look at non-template functions, as it is the predefined,
> + // non-templated allocation function we are trying to declare here.
> + if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) {
> + QualType InitialParamType =
> Context.getCanonicalType(
> - Func->getParamDecl(0)->getType().getUnqualifiedType()) == Argument)
> - return;
> + Func->getParamDecl(0)->getType().getUnqualifiedType());
> + // FIXME: Do we need to check for default arguments here?
> + if (Func->getNumParams() == 1 && InitialParamType == Argument)
> + return;
> + }
> }
> }
>
>
> Added: cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp?rev=95220&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp (added)
> +++ cfe/trunk/test/SemaCXX/new-delete-predefined-decl.cpp Wed Feb 3 05:02:14 2010
> @@ -0,0 +1,18 @@
> +// RUN: %clang_cc1 -DTEMPLATE_OVERLOAD -fsyntax-only -verify %s
> +
> +#include <stddef.h>
> +
> +// Note that each test must be run separately so it can be the first operator
> +// new declaration in the file.
Did you also want a second run line without TEMPLATE_OVERLOAD, e.g.,
RUN: %clang_cc1 -fsyntax-only -verify %s
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100203/6b448a7c/attachment.html>
More information about the cfe-commits
mailing list