|
@@ -2593,28 +2593,39 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
|
|
getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
|
|
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,
|
|
FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,
|