[PATCH] D117091: [Clang] Add attributes alloc_size and alloc_align to mm_malloc

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 30 10:45:06 PST 2022


xbolva00 updated this revision to Diff 404394.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117091/new/

https://reviews.llvm.org/D117091

Files:
  clang/lib/Headers/mm_malloc.h
  clang/test/Headers/Inputs/include/malloc.h
  clang/test/Headers/mm_malloc.c


Index: clang/test/Headers/mm_malloc.c
===================================================================
--- /dev/null
+++ 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;
+}
Index: clang/test/Headers/Inputs/include/malloc.h
===================================================================
--- /dev/null
+++ clang/test/Headers/Inputs/include/malloc.h
@@ -0,0 +1,5 @@
+#if defined(__MINGW32__)
+void *__mingw_aligned_malloc(size_t, size_t)
+#elif defined(_WIN32)
+void *_aligned_malloc(size_t, size_t);
+#endif
\ No newline at end of file
Index: clang/lib/Headers/mm_malloc.h
===================================================================
--- clang/lib/Headers/mm_malloc.h
+++ clang/lib/Headers/mm_malloc.h
@@ -28,9 +28,9 @@
 
 #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);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117091.404394.patch
Type: text/x-patch
Size: 1529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220130/a8b46294/attachment-0001.bin>


More information about the cfe-commits mailing list