Skip to content

Commit 48c2dd8

Browse files
committed
Replace alignment_of_long_double with C11 alignof if possible
This removes a static variable in a static function and uses C11 `alignof` instead to get a compile-time value. Since we don't currently require C11 we keep the old implementation as fallback. Also fixes this compiler warning: ``` opal_copy_functions_heterogeneous.c:495:1: warning: function declaration isn't a prototype [-Wstrict-prototypes] 495 | alignment_of_long_double() { | ^~~~~~~~~~~~~~~~~~~~~~~~ ``` by adding `void` as parameter. Signed-off-by: Joseph Schuchart <[email protected]>
1 parent ff12b69 commit 48c2dd8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

opal/datatype/opal_copy_functions_heterogeneous.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* and Technology (RIST). All rights reserved.
99
* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
1010
* Copyright (c) 2021 IBM Corporation. All rights reserved.
11+
* Copyright (c) 2024 Stony Brook University. All rights reserved.
1112
* $COPYRIGHT$
1213
*
1314
* Additional copyrights may follow
@@ -481,18 +482,23 @@ f128_to_f80(unsigned char *f80_buf_to, const unsigned char *f128_buf_from, ssize
481482
#define LDBL_INFO_MASK (OPAL_ARCH_LDMANTDIGISxx | OPAL_ARCH_LDEXPSIZEISxx)
482483

483484
#ifdef HAVE___FLOAT128
484-
/*
485-
* I'm not sure about the portability of alignof() so I'm handling things
486-
* like the possibility of sizeof(long double) == 12 in a slower way. The
487-
* alignment requirement in that case would be 4 (largest power of 2 that
488-
* divides into the sizeof).
485+
#if __STDC_VERSION__ >= 201101L
486+
#include <stdalign.h>
487+
static inline
488+
size_t
489+
alignment_of_long_double(void) {
490+
return alignof(long double);
491+
}
492+
#else // __STDC_VERSION__ >= 201101L
493+
/**
494+
* No support for C11 so try to compute alignment manually.
489495
*
490496
* And saving it static to just compute it once without running a loop
491497
* every call.
492498
*/
493499
static inline
494500
size_t
495-
alignment_of_long_double() {
501+
alignment_of_long_double(void) {
496502
static size_t val = 0;
497503

498504
if (val == 0) {
@@ -503,7 +509,8 @@ alignment_of_long_double() {
503509
}
504510
return val;
505511
}
506-
#endif
512+
#endif // __STDC_VERSION__ >= 201101L
513+
#endif // HAVE___FLOAT128
507514

508515
// ldbl_to_f128 (copies a long double(from_arch format) to a float128(local_endian))
509516
static inline

0 commit comments

Comments
 (0)