diff options
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 83474cb7f83..49e25de2ac9 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2593,28 +2593,39 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone; } - QualType FnType = Context.getFunctionType(Return, Params, EPI); - FunctionDecl *Alloc = - FunctionDecl::Create(Context, GlobalCtx, SourceLocation(), - SourceLocation(), Name, - FnType, /*TInfo=*/nullptr, SC_None, false, true); - Alloc->setImplicit(); - - // Implicit sized deallocation functions always have default visibility. - Alloc->addAttr(VisibilityAttr::CreateImplicit(Context, - VisibilityAttr::Default)); - - llvm::SmallVector<ParmVarDecl*, 3> ParamDecls; - for (QualType T : Params) { - ParamDecls.push_back( - ParmVarDecl::Create(Context, Alloc, SourceLocation(), SourceLocation(), - nullptr, T, /*TInfo=*/nullptr, SC_None, nullptr)); - ParamDecls.back()->setImplicit(); - } - Alloc->setParams(ParamDecls); - - Context.getTranslationUnitDecl()->addDecl(Alloc); - IdResolver.tryAddTopLevelDecl(Alloc, Name); + auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) { + QualType FnType = Context.getFunctionType(Return, Params, EPI); + FunctionDecl *Alloc = FunctionDecl::Create( + Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, + FnType, /*TInfo=*/nullptr, SC_None, false, true); + Alloc->setImplicit(); + + // Implicit sized deallocation functions always have default visibility. + Alloc->addAttr( + VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default)); + + llvm::SmallVector<ParmVarDecl *, 3> ParamDecls; + for (QualType T : Params) { + ParamDecls.push_back(ParmVarDecl::Create( + Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T, + /*TInfo=*/nullptr, SC_None, nullptr)); + ParamDecls.back()->setImplicit(); + } + Alloc->setParams(ParamDecls); + if (ExtraAttr) + Alloc->addAttr(ExtraAttr); + Context.getTranslationUnitDecl()->addDecl(Alloc); + IdResolver.tryAddTopLevelDecl(Alloc, Name); + }; + + if (!LangOpts.CUDA) + CreateAllocationFunctionDecl(nullptr); + else { + // Host and device get their own declaration so each can be + // defined or re-declared independently. + CreateAllocationFunctionDecl(CUDAHostAttr::CreateImplicit(Context)); + CreateAllocationFunctionDecl(CUDADeviceAttr::CreateImplicit(Context)); + } } FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc, |