Skip to content

Commit 4d26b40

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 4d26b40

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

opal/datatype/opal_copy_functions_heterogeneous.c

Lines changed: 13 additions & 8 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
@@ -480,19 +481,23 @@ f128_to_f80(unsigned char *f80_buf_to, const unsigned char *f128_buf_from, ssize
480481
)
481482
#define LDBL_INFO_MASK (OPAL_ARCH_LDMANTDIGISxx | OPAL_ARCH_LDEXPSIZEISxx)
482483

483-
#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).
484+
#if __STDC_VERSION__ >= 201101L
485+
#include <stdalign.h>
486+
static inline
487+
size_t
488+
alignment_of_long_double(void) {
489+
return alignof(long double);
490+
}
491+
#else // __STDC_VERSION__ >= 201101L
492+
/**
493+
* No support for C11 so try to compute alignment manually.
489494
*
490495
* And saving it static to just compute it once without running a loop
491496
* every call.
492497
*/
493498
static inline
494499
size_t
495-
alignment_of_long_double() {
500+
alignment_of_long_double(void) {
496501
static size_t val = 0;
497502

498503
if (val == 0) {
@@ -503,7 +508,7 @@ alignment_of_long_double() {
503508
}
504509
return val;
505510
}
506-
#endif
511+
#endif // __STDC_VERSION__ >= 201101L
507512

508513
// ldbl_to_f128 (copies a long double(from_arch format) to a float128(local_endian))
509514
static inline

0 commit comments

Comments
 (0)