From 9f1e2ee46251b09565eb87124aa836291aaf799d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bolvansk=C3=BD?= Date: Wed, 21 Apr 2021 00:10:52 +0200 Subject: [PATCH] [Clang, builtins] Added aligned_alloc, memalign support --- clang/include/clang/Basic/Builtins.def | 4 ++++ clang/test/CodeGen/aligned_alloc-libcall.c | 12 ++++++++++++ clang/test/CodeGen/memalign-libcall.c | 12 ++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 clang/test/CodeGen/aligned_alloc-libcall.c create mode 100644 clang/test/CodeGen/memalign-libcall.c diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index 92da70ea05db..ead84e2e6279 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 000000000000..ee44fc38b393 --- /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 000000000000..ec040456d885 --- /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