Skip to content

Commit 869c1d7

Browse files
ketteniststellar
authored andcommitted
[Clang] Fix the guaranteed alignment of memory returned by malloc/new on OpenBSD
The guaranteed alignment is 16 bytes on OpenBSD. (cherry picked from commit c7ee0b8)
1 parent 5c4cf01 commit 869c1d7

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
@@ -199,6 +199,9 @@
199199
// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
200200
// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
201201

202+
// RUN: %clang_cc1 -E -dM -triple=arm-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-OPENBSD-CXX %s
203+
// ARM-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
204+
202205
// 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
203206
// ARM-APCS-GNU: #define __INTPTR_TYPE__ int
204207
// 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
@@ -1176,3 +1176,6 @@
11761176
// PPC-DARWIN:#define __WINT_WIDTH__ 32
11771177
// PPC-DARWIN:#define __powerpc__ 1
11781178
// PPC-DARWIN:#define __ppc__ 1
1179+
1180+
// RUN: %clang_cc1 -E -dM -triple=powerpc-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix PPC-OPENBSD-CXX %s
1181+
// 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
@@ -1732,3 +1732,6 @@
17321732
// X86_64-NETBSD:#define __amd64__ 1
17331733
// X86_64-NETBSD:#define __x86_64 1
17341734
// X86_64-NETBSD:#define __x86_64__ 1
1735+
1736+
// RUN: %clang_cc1 -E -dM -triple=i386-unknown-openbsd -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix I386-OPENBSD-CXX %s
1737+
// I386-OPENBSD-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL

0 commit comments

Comments
 (0)