Skip to content

Commit c7ee0b8

Browse files
kettenisbrad0
authored andcommitted
[Clang] Fix the guaranteed alignment of memory returned by malloc/new on OpenBSD
The guaranteed alignment is 16 bytes on OpenBSD.
1 parent 3b3dd76 commit c7ee0b8

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
6969
// From the glibc documentation, on GNU systems, malloc guarantees 16-byte
7070
// alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
7171
// https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
72-
// This alignment guarantee also applies to Windows and Android. On Darwin,
73-
// the alignment is 16 bytes on both 64-bit and 32-bit systems.
72+
// This alignment guarantee also applies to Windows and Android. On Darwin
73+
// and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems.
7474
if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
7575
NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
76-
else if (T.isOSDarwin())
76+
else if (T.isOSDarwin() || T.isOSOpenBSD())
7777
NewAlign = 128;
7878
else
7979
NewAlign = 0; // Infer from basic type alignment.

clang/test/Preprocessor/init-arm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@
198198
// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
199199
// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
200200

201+
// RUN: %clang_cc1 -E -dM -triple=arm-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-OPENBSD-CXX %s
202+
// ARM-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
203+
201204
// RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix ARM-APCS-GNU %s
202205
// ARM-APCS-GNU: #define __INTPTR_TYPE__ int
203206
// ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int

clang/test/Preprocessor/init-ppc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,3 +1171,6 @@
11711171
// PPC-DARWIN:#define __WINT_WIDTH__ 32
11721172
// PPC-DARWIN:#define __powerpc__ 1
11731173
// PPC-DARWIN:#define __ppc__ 1
1174+
1175+
// RUN: %clang_cc1 -E -dM -triple=powerpc-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix PPC-OPENBSD-CXX %s
1176+
// PPC-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL

clang/test/Preprocessor/init-x86.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,3 +1717,6 @@
17171717
// X86_64-NETBSD:#define __amd64__ 1
17181718
// X86_64-NETBSD:#define __x86_64 1
17191719
// X86_64-NETBSD:#define __x86_64__ 1
1720+
1721+
// RUN: %clang_cc1 -E -dM -triple=i386-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix I386-OPENBSD-CXX %s
1722+
// I386-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL

0 commit comments

Comments
 (0)