aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDecl.cpp4
-rw-r--r--clang/test/CodeGen/alloc-fns-alignment.c7
2 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 59726ad..cc3417d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15150,6 +15150,10 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
// Add known guaranteed alignment for allocation functions.
switch (BuiltinID) {
case Builtin::BIaligned_alloc:
+ if (!FD->hasAttr<AllocAlignAttr>())
+ FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
+ FD->getLocation()));
+ LLVM_FALLTHROUGH;
case Builtin::BIcalloc:
case Builtin::BImalloc:
case Builtin::BImemalign:
diff --git a/clang/test/CodeGen/alloc-fns-alignment.c b/clang/test/CodeGen/alloc-fns-alignment.c
index 1ce0cfb..b19cf86 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -48,13 +48,14 @@ void *aligned_alloc_large_constant_test(size_t n) {
// ALIGN16: align 16 i8* @realloc
// CHECK-LABEL: @aligned_alloc_variable_test
-// ALIGN16: align 16 i8* @aligned_alloc
+// ALIGN16: %[[ALLOCATED:.*]] = call align 16 i8* @aligned_alloc({{i32|i64}} %[[ALIGN:.*]], {{i32|i64}} %[[NBYTES:.*]])
+// ALIGN16-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ]
// CHECK-LABEL: @aligned_alloc_constant_test
// ALIGN16: align 16 i8* @aligned_alloc
// CHECK-LABEL: @aligned_alloc_large_constant_test
-// ALIGN16: align 16 i8* @aligned_alloc
+// ALIGN16: align 4096 i8* @aligned_alloc
// CHECK-LABEL: @malloc_test
// ALIGN8: align 8 i8* @malloc
@@ -72,7 +73,7 @@ void *aligned_alloc_large_constant_test(size_t n) {
// ALIGN8: align 8 i8* @aligned_alloc
// CHECK-LABEL: @aligned_alloc_large_constant_test
-// ALIGN8: align 8 i8* @aligned_alloc
+// ALIGN8: align 4096 i8* @aligned_alloc
// NOBUILTIN-MALLOC: declare i8* @malloc
// NOBUILTIN-CALLOC: declare i8* @calloc