Skip to content

Commit 8bec8f3

Browse files
committed
Auto-detect __builtin_complex
This is needed to implement the CMPLX* macros correctly. Signed-off-by: Keith Packard <[email protected]>
1 parent 7d5dc7d commit 8bec8f3

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ picolibc_flag(_HAVE_CC_INHIBIT_LOOP_TO_LIBCALL)
194194
# Compiler supports _Complex
195195
picolibc_flag(_HAVE_COMPLEX)
196196

197+
# Compiler supports __builtin_complex
198+
picolibc_flag(_HAVE_BUILTIN_COMPLEX)
199+
197200
# Compiler supports format function attribute
198201
picolibc_flag(_HAVE_FORMAT_ATTRIBUTE 1)
199202

cmake/have-builtin-complex.c

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
static double _Complex test(double r, double i) { return __builtin_complex(r, i); }
2+
int main(void) { test(1.0, 2.0); return 0; }

meson.build

+8
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,13 @@ float _Complex test(float _Complex z) { return z; }
811811
'''
812812
have_complex = cc.compiles(complex_code, name : 'supports _Complex', args: core_c_args)
813813

814+
builtin_complex_code = '''
815+
#include <stddef.h>
816+
double _Complex test(double r, double i) { return __builtin_complex(r, i); }
817+
'''
818+
819+
have_builtin_complex = have_complex and cc.compiles(builtin_complex_code, name : 'supports __builtin_complex', args: core_c_args)
820+
814821
# CompCert does not have __builtin_expect
815822
builtin_expect_code = '''
816823
volatile int a = 42;
@@ -1050,6 +1057,7 @@ conf_data.set('_HAVE_BITFIELDS_IN_PACKED_STRUCTS', have_bitfields_in_packed_stru
10501057
conf_data.set('_HAVE_BUILTIN_MUL_OVERFLOW', have_builtin_mul_overflow, description: 'Compiler has __builtin_mul_overflow')
10511058
conf_data.set('_HAVE_BUILTIN_ADD_OVERFLOW', have_builtin_add_overflow, description: 'Compiler has __builtin_add_overflow')
10521059
conf_data.set('_HAVE_COMPLEX', have_complex, description: 'Compiler supports _Complex')
1060+
conf_data.set('_HAVE_BUILTIN_COMPLEX', have_builtin_complex, description: 'Compiler has __builtin_complex')
10531061
conf_data.set('_HAVE_BUILTIN_EXPECT', have_builtin_expect, description: 'Compiler has __builtin_expect')
10541062
conf_data.set('_HAVE_ALLOC_SIZE', have_alloc_size, description: 'The compiler REALLY has the attribute __alloc_size__')
10551063
conf_data.set('_HAVE_ATTRIBUTE_ALWAYS_INLINE',

picolibc.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
/* Compiler supports _Complex */
122122
#cmakedefine _HAVE_COMPLEX
123123

124+
/* Compiler supports __builtin_complex */
125+
#cmakedefine _HAVE_BUILTIN_COMPLEX
126+
124127
#cmakedefine _HAVE_FCNTL
125128

126129
#cmakedefine _HAVE_FORMAT_ATTRIBUTE

0 commit comments

Comments
 (0)