[clang] 85ba583 - [NFCI][clang] Move allocation alignment manifestation for malloc-like into Sema from Codegen
Roman Lebedev via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 10 10:50:15 PDT 2021
Author: Roman Lebedev
Date: 2021-09-10T20:49:28+03:00
New Revision: 85ba583eba1902c386a55f5565f3c721bd6bcb23
URL: https://github.com/llvm/llvm-project/commit/85ba583eba1902c386a55f5565f3c721bd6bcb23
DIFF: https://github.com/llvm/llvm-project/commit/85ba583eba1902c386a55f5565f3c721bd6bcb23.diff
LOG: [NFCI][clang] Move allocation alignment manifestation for malloc-like into Sema from Codegen
... so that it happens right next to `AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()`,
which is good for consistency.
Added:
Modified:
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1ddd4d160b4bd..deb688513fd18 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2066,24 +2066,6 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
// allows it to work on indirect virtual function calls.
if (AttrOnCallSite && TargetDecl->hasAttr<NoMergeAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
-
- // Add known guaranteed alignment for allocation functions.
- if (unsigned BuiltinID = Fn->getBuiltinID()) {
- switch (BuiltinID) {
- case Builtin::BIaligned_alloc:
- case Builtin::BIcalloc:
- case Builtin::BImalloc:
- case Builtin::BImemalign:
- case Builtin::BIrealloc:
- case Builtin::BIstrdup:
- case Builtin::BIstrndup:
- RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
- Context.getTargetInfo().getCharWidth());
- break;
- default:
- break;
- }
- }
}
// 'const', 'pure' and 'noalias' attributed functions are also nounwind.
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 92c1a37fdab96..59726ad67fbb6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15146,6 +15146,30 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
else
FD->addAttr(CUDAHostAttr::CreateImplicit(Context, FD->getLocation()));
}
+
+ // Add known guaranteed alignment for allocation functions.
+ switch (BuiltinID) {
+ case Builtin::BIaligned_alloc:
+ case Builtin::BIcalloc:
+ case Builtin::BImalloc:
+ case Builtin::BImemalign:
+ case Builtin::BIrealloc:
+ case Builtin::BIstrdup:
+ case Builtin::BIstrndup: {
+ if (!FD->hasAttr<AssumeAlignedAttr>()) {
+ unsigned NewAlign = Context.getTargetInfo().getNewAlign() /
+ Context.getTargetInfo().getCharWidth();
+ IntegerLiteral *Alignment = IntegerLiteral::Create(
+ Context, Context.MakeIntValue(NewAlign, Context.UnsignedIntTy),
+ Context.UnsignedIntTy, FD->getLocation());
+ FD->addAttr(AssumeAlignedAttr::CreateImplicit(
+ Context, Alignment, /*Offset=*/nullptr, FD->getLocation()));
+ }
+ break;
+ }
+ default:
+ break;
+ }
}
AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
More information about the cfe-commits
mailing list