[clang] 9f1e2ee - [Clang, builtins] Added aligned_alloc, memalign support

Dávid Bolvanský via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 20 15:12:06 PDT 2021


Author: Dávid Bolvanský
Date: 2021-04-21T00:11:54+02:00
New Revision: 9f1e2ee46251b09565eb87124aa836291aaf799d

URL: https://github.com/llvm/llvm-project/commit/9f1e2ee46251b09565eb87124aa836291aaf799d
DIFF: https://github.com/llvm/llvm-project/commit/9f1e2ee46251b09565eb87124aa836291aaf799d.diff

LOG: [Clang, builtins] Added aligned_alloc, memalign support

Added: 
    clang/test/CodeGen/aligned_alloc-libcall.c
    clang/test/CodeGen/memalign-libcall.c

Modified: 
    clang/include/clang/Basic/Builtins.def

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index 92da70ea05db3..ead84e2e62797 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -980,6 +980,8 @@ LIBBUILTIN(strtol, "LicC*c**i",   "f",     "stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(strtoll, "LLicC*c**i", "f",     "stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(strtoul, "ULicC*c**i", "f",     "stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(strtoull, "ULLicC*c**i", "f",   "stdlib.h", ALL_LANGUAGES)
+// C11 stdlib.h
+LIBBUILTIN(aligned_alloc, "v*zz", "f",     "stdlib.h", ALL_LANGUAGES)
 // C99 string.h
 LIBBUILTIN(memcpy, "v*v*vC*z",    "f",     "string.h", ALL_LANGUAGES)
 LIBBUILTIN(memcmp, "ivC*vC*z",    "f",     "string.h", ALL_LANGUAGES)
@@ -1061,6 +1063,8 @@ LIBBUILTIN(longjmp, "vJi",        "frT",   "setjmp.h", ALL_LANGUAGES)
 // all languages, because losing this attribute would result in miscompilation
 // when these functions are used in non-GNU mode. PR16138.
 LIBBUILTIN(alloca, "v*z",         "f",     "stdlib.h", ALL_GNU_LANGUAGES)
+// POSIX malloc.h
+LIBBUILTIN(memalign, "v*zz",      "f",     "malloc.h", ALL_GNU_LANGUAGES)
 // POSIX string.h
 LIBBUILTIN(memccpy, "v*v*vC*iz",  "f",     "string.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(mempcpy, "v*v*vC*z",   "f",     "string.h", ALL_GNU_LANGUAGES)

diff  --git a/clang/test/CodeGen/aligned_alloc-libcall.c b/clang/test/CodeGen/aligned_alloc-libcall.c
new file mode 100644
index 0000000000000..ee44fc38b393f
--- /dev/null
+++ b/clang/test/CodeGen/aligned_alloc-libcall.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fno-builtin-aligned_alloc -emit-llvm < %s | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *aligned_alloc(size_t, size_t);
+
+void *test(size_t alignment, size_t size) {
+  // CHECK: call i8* @aligned_alloc{{.*}} #2
+  return aligned_alloc(alignment, size);
+}
+
+// CHECK: attributes #2 = { nobuiltin "no-builtin-aligned_alloc" } 
\ No newline at end of file

diff  --git a/clang/test/CodeGen/memalign-libcall.c b/clang/test/CodeGen/memalign-libcall.c
new file mode 100644
index 0000000000000..ec040456d885d
--- /dev/null
+++ b/clang/test/CodeGen/memalign-libcall.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fno-builtin-memalign -emit-llvm < %s | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *memalign(size_t, size_t);
+
+void *test(size_t alignment, size_t size) {
+  // CHECK: call i8* @memalign{{.*}} #2
+  return memalign(alignment, size);
+}
+
+// CHECK: attributes #2 = { nobuiltin "no-builtin-memalign" } 
\ No newline at end of file


        


More information about the cfe-commits mailing list