x86-64: Fix the dtv field load for x32 [BZ #31184]
[glibc.git] / malloc / tst-aligned-alloc.c
blob8bd6527147eb8760d7ba1356e98a7fbcd48b66e3
1 /* Test for C17 alignment requirements.
2 Copyright (C) 2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <malloc.h>
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <libc-diag.h>
26 #include <support/check.h>
28 static int
29 do_test (void)
31 void *p1;
32 void *p2;
33 void *p3;
34 void *p4;
35 void *p5;
37 errno = 0;
39 /* The implementation supports alignments that are non-negative powers of 2.
40 We test 5 distinct conditions here:
41 - A non-negative power of 2 alignment e.g. 64.
42 - A degenerate zero power of 2 alignment e.g. 1.
43 - A non-power-of-2 alignment e.g. 65.
44 - A zero alignment.
45 - A corner case SIZE_MAX / 2 + 1 alignment.
48 p1 = aligned_alloc (64, 64);
50 if (p1 == NULL)
51 FAIL_EXIT1 ("aligned_alloc(64, 64) failed");
53 p2 = aligned_alloc (1, 64);
55 if (p2 == NULL)
56 FAIL_EXIT1 ("aligned_alloc(1, 64) failed");
58 p3 = aligned_alloc (65, 64);
60 if (p3 != NULL)
61 FAIL_EXIT1 ("aligned_alloc(65, 64) did not fail");
63 p4 = aligned_alloc (0, 64);
65 if (p4 != NULL)
66 FAIL_EXIT1 ("aligned_alloc(0, 64) did not fail");
68 /* This is an alignment like 0x80000000...UL */
69 p5 = aligned_alloc (SIZE_MAX / 2 + 1, 64);
71 if (p5 != NULL)
72 FAIL_EXIT1 ("aligned_alloc(SIZE_MAX/2+1, 64) did not fail");
74 free (p1);
75 free (p2);
76 return 0;
79 #define TEST_FUNCTION do_test ()
80 #include "../test-skeleton.c"