[clang] 74b1c4c - [clang] added alloc allign attr to memalign

Dávid Bolvanský via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 5 02:47:30 PST 2022


Author: Dávid Bolvanský
Date: 2022-02-05T11:46:56+01:00
New Revision: 74b1c4c36740fe94953ef648e40df7dd9e9a9c7d

URL: https://github.com/llvm/llvm-project/commit/74b1c4c36740fe94953ef648e40df7dd9e9a9c7d
DIFF: https://github.com/llvm/llvm-project/commit/74b1c4c36740fe94953ef648e40df7dd9e9a9c7d.diff

LOG: [clang] added alloc allign attr to memalign

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/test/CodeGen/alloc-fns-alignment.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a86947aa5fbfc..f2871d82b0409 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15315,6 +15315,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
 
     // Add known guaranteed alignment for allocation functions.
     switch (BuiltinID) {
+    case Builtin::BImemalign:
     case Builtin::BIaligned_alloc:
       if (!FD->hasAttr<AllocAlignAttr>())
         FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
@@ -15322,7 +15323,6 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
       LLVM_FALLTHROUGH;
     case Builtin::BIcalloc:
     case Builtin::BImalloc:
-    case Builtin::BImemalign:
     case Builtin::BIrealloc:
     case Builtin::BIstrdup:
     case Builtin::BIstrndup: {

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c b/clang/test/CodeGen/alloc-fns-alignment.c
index 8ab0610accf03..29d6e9e4fb380 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  -emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc -emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc -emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-memalign -emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MEMALIGN
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -13,6 +14,7 @@ void *malloc(size_t);
 void *calloc(size_t, size_t);
 void *realloc(void *, size_t);
 void *aligned_alloc(size_t, size_t);
+void *memalign(size_t, size_t);
 
 void *malloc_test(size_t n) {
   return malloc(n);
@@ -30,6 +32,10 @@ void *aligned_alloc_variable_test(size_t n, size_t a) {
   return aligned_alloc(a, n);
 }
 
+void *memalign_variable_test(size_t n, size_t a) {
+  return memalign(a, n);
+}
+
 void *aligned_alloc_constant_test(size_t n) {
   return aligned_alloc(8, n);
 }
@@ -38,6 +44,10 @@ void *aligned_alloc_large_constant_test(size_t n) {
   return aligned_alloc(4096, n);
 }
 
+void *memalign_large_constant_test(size_t n) {
+  return memalign(4096, n);
+}
+
 // CHECK-LABEL: @malloc_test
 // ALIGN16: align 16 i8* @malloc
 
@@ -51,12 +61,19 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // ALIGN16:      %[[ALLOCATED:.*]] = call align 16 i8* @aligned_alloc({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]])
 // ALIGN16-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ]
 
+// CHECK-LABEL: @memalign_variable_test
+// ALIGN16:      %[[ALLOCATED:.*]] = call align 16 i8* @memalign({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[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 4096 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_large_constant_test
+// ALIGN16: align 4096 i8* @memalign
+
 // CHECK-LABEL: @malloc_test
 // ALIGN8: align 8 i8* @malloc
 
@@ -69,13 +86,20 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // CHECK-LABEL: @aligned_alloc_variable_test
 // ALIGN8: align 8 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_variable_test
+// ALIGN8: align 8 i8* @memalign
+
 // CHECK-LABEL: @aligned_alloc_constant_test
 // ALIGN8: align 8 i8* @aligned_alloc
 
 // CHECK-LABEL: @aligned_alloc_large_constant_test
 // ALIGN8: align 4096 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_large_constant_test
+// ALIGN8: align 4096 i8* @memalign
+
 // NOBUILTIN-MALLOC: declare i8* @malloc
 // NOBUILTIN-CALLOC: declare i8* @calloc
 // NOBUILTIN-REALLOC: declare i8* @realloc
 // NOBUILTIN-ALIGNED_ALLOC: declare i8* @aligned_alloc
+// NOBUILTIN-MEMALIGN: declare i8* @memalign


        


More information about the cfe-commits mailing list