+
+# Return 1 if the target has <pthread.h>.
+
+proc check_effective_target_pthread_h { } {
+ return [check_no_compiler_messages pthread_h assembly {
+ #include <pthread.h>
+ }]
+}
+
+# Return 1 if the target can truncate a file from a file-descriptor,
+# as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
+# chsize. We test for a trivially functional truncation; no stubs.
+# As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
+# different function to be used.
+
+proc check_effective_target_fd_truncate { } {
+ set prog {
+ #define _FILE_OFFSET_BITS 64
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ int main ()
+ {
+ FILE *f = fopen ("tst.tmp", "wb");
+ int fd;
+ const char t[] = "test writing more than ten characters";
+ char s[11];
+ fd = fileno (f);
+ write (fd, t, sizeof (t) - 1);
+ lseek (fd, 0, 0);
+ if (ftruncate (fd, 10) != 0)
+ exit (1);
+ close (fd);
+ f = fopen ("tst.tmp", "rb");
+ if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
+ exit (1);
+ exit (0);
+ }
+ }
+
+ if { [check_runtime ftruncate $prog] } {
+ return 1;
+ }
+
+ regsub "ftruncate" $prog "chsize" prog
+ return [check_runtime chsize $prog]
+}
+
+# Add to FLAGS all the target-specific flags needed to access the c99 runtime.
+
+proc add_options_for_c99_runtime { flags } {
+ if { [istarget *-*-solaris2*] } {
+ return "$flags -std=c99"
+ }
+ if { [istarget powerpc-*-darwin*] } {
+ return "$flags -mmacosx-version-min=10.3"
+ }
+ return $flags
+}
+
+# Return 1 if the target provides a full C99 runtime.
+
+proc check_effective_target_c99_runtime { } {
+ return [check_cached_effective_target c99_runtime {
+ global srcdir
+
+ set file [open "$srcdir/gcc.dg/builtins-config.h"]
+ set contents [read $file]
+ close $file
+ append contents {
+ #ifndef HAVE_C99_RUNTIME
+ #error FOO
+ #endif
+ }
+ check_no_compiler_messages_nocache c99_runtime assembly \
+ $contents [add_options_for_c99_runtime ""]
+ }]
+}
+
+# Return 1 if target wchar_t is at least 4 bytes.
+
+proc check_effective_target_4byte_wchar_t { } {
+ return [check_no_compiler_messages 4byte_wchar_t object {
+ int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
+ }]
+}
+
+# Return 1 if the target supports automatic stack alignment.
+
+proc check_effective_target_automatic_stack_alignment { } {
+ if { [istarget i?86*-*-*]
+ || [istarget x86_64-*-*] } then {
+ return 1
+ } else {
+ return 0
+ }
+}
+
+# Return 1 if avx instructions can be compiled.
+
+proc check_effective_target_avx { } {
+ return [check_no_compiler_messages avx object {
+ void _mm256_zeroall (void)
+ {
+ __builtin_ia32_vzeroall ();
+ }
+ } "-O2 -mavx" ]
+}
+
+# Return 1 if C wchar_t type is compatible with char16_t.
+
+proc check_effective_target_wchar_t_char16_t_compatible { } {
+ return [check_no_compiler_messages wchar_t_char16_t object {
+ __WCHAR_TYPE__ wc;
+ __CHAR16_TYPE__ *p16 = &wc;
+ char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
+ }]
+}
+
+# Return 1 if C wchar_t type is compatible with char32_t.
+
+proc check_effective_target_wchar_t_char32_t_compatible { } {
+ return [check_no_compiler_messages wchar_t_char32_t object {
+ __WCHAR_TYPE__ wc;
+ __CHAR32_TYPE__ *p32 = &wc;
+ char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
+ }]
+}
+
+# Return 1 if pow10 function exists.
+
+proc check_effective_target_pow10 { } {
+ return [check_runtime pow10 {
+ #include <math.h>
+ int main () {
+ double x;
+ x = pow10 (1);
+ return 0;
+ }
+ } "-lm" ]
+}
+
+# Return 1 if current options generate DFP instructions, 0 otherwise.
+
+proc check_effective_target_hard_dfp {} {
+ return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
+ _Decimal64 x, y, z;
+ void foo (void) { z = x + y; }
+ }]
+}