Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -2593,28 +2593,40 @@ 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(); + auto CreateAllocationFunctionDecl = [&]() { + 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)); + // Implicit sized deallocation functions always have default visibility. + Alloc->addAttr( + VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default)); - llvm::SmallVector 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); + llvm::SmallVector 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); + return Alloc; + }; + FunctionDecl *Alloc = CreateAllocationFunctionDecl(); + if (LangOpts.CUDA) + Alloc->addAttr(CUDAHostAttr::CreateImplicit(Context)); Context.getTranslationUnitDecl()->addDecl(Alloc); IdResolver.tryAddTopLevelDecl(Alloc, Name); + + if (LangOpts.CUDA) { + Alloc = CreateAllocationFunctionDecl(); + Alloc->addAttr(CUDADeviceAttr::CreateImplicit(Context)); + Context.getTranslationUnitDecl()->addDecl(Alloc); + IdResolver.tryAddTopLevelDecl(Alloc, Name); + } } FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,