[clang] 2c91754 - [Clang] Add attributes alloc_size and alloc_align to mm_malloc
Dávid Bolvanský via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 17 10:59:46 PST 2022
Author: Dávid Bolvanský
Date: 2022-02-17T19:59:18+01:00
New Revision: 2c91754a13f333d7fe9f9d3d40fb618e40c48cab
URL: https://github.com/llvm/llvm-project/commit/2c91754a13f333d7fe9f9d3d40fb618e40c48cab
DIFF: https://github.com/llvm/llvm-project/commit/2c91754a13f333d7fe9f9d3d40fb618e40c48cab.diff
LOG: [Clang] Add attributes alloc_size and alloc_align to mm_malloc
LLVM optimizes source codes with mm_malloc better, especially due to alignment info.
alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
alloc size https://clang.llvm.org/docs/AttributeReference.html#alloc-size
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D117091
Added:
clang/test/Headers/Inputs/include/malloc.h
clang/test/Headers/mm_malloc.c
Modified:
clang/lib/Headers/mm_malloc.h
Removed:
################################################################################
diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index 933dbaacade59..d32fe59416277 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -28,9 +28,9 @@ extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size
#if !(defined(_WIN32) && defined(_mm_malloc))
static __inline__ void *__attribute__((__always_inline__, __nodebug__,
- __malloc__))
-_mm_malloc(size_t __size, size_t __align)
-{
+ __malloc__, __alloc_size__(1),
+ __alloc_align__(2)))
+_mm_malloc(size_t __size, size_t __align) {
if (__align == 1) {
return malloc(__size);
}
diff --git a/clang/test/Headers/Inputs/include/malloc.h b/clang/test/Headers/Inputs/include/malloc.h
new file mode 100644
index 0000000000000..590263bb010a3
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/malloc.h
@@ -0,0 +1,7 @@
+#if defined(__MINGW32__)
+void *__mingw_aligned_malloc(size_t, size_t);
+void __mingw_aligned_free(void *);
+#elif defined(_WIN32)
+void *_aligned_malloc(size_t, size_t);
+void _aligned_free(void *);
+#endif
diff --git a/clang/test/Headers/mm_malloc.c b/clang/test/Headers/mm_malloc.c
new file mode 100644
index 0000000000000..a436ff3013bf6
--- /dev/null
+++ b/clang/test/Headers/mm_malloc.c
@@ -0,0 +1,12 @@
+
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include %s -emit-llvm -O1 -triple x86_64-linux-gnu -o - | FileCheck %s
+#include <mm_malloc.h>
+
+_Bool align_test(void) {
+// CHECK-LABEL: @align_test(
+// CHECK: ret i1 true
+ void *p = _mm_malloc(1024, 16);
+ _Bool ret = ((__UINTPTR_TYPE__)p % 16) == 0;
+ _mm_free(p);
+ return ret;
+}
More information about the cfe-commits
mailing list