Revert "[compiler-rt] [builtins] Detect _Float16 support at compile time"

This reverts commit ce6d40f5c23923a807388c58b82b4c343eced0ce.

Revert due to it broke the sanitizer-windows buildbot: https://lab.llvm.org/buildbot/#/builders/127/builds/33583/steps/4/logs/stdio

GitOrigin-RevId: b17c89d1511f14b864ee680577a7b68363d672f9
diff --git a/cmake/builtin-config-ix.cmake b/cmake/builtin-config-ix.cmake
index ce7e0a7..9cbadf3 100644
--- a/cmake/builtin-config-ix.cmake
+++ b/cmake/builtin-config-ix.cmake
@@ -22,6 +22,14 @@
 }
 ")
 
+builtin_check_c_compiler_source(COMPILER_RT_HAS_FLOAT16
+"
+_Float16 foo(_Float16 x) {
+ return x;
+}
+"
+)
+
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ASM_LSE
 "
 asm(\".arch armv8-a+lse\");
diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt
index 8efc6d1..0b91b4c 100644
--- a/lib/builtins/CMakeLists.txt
+++ b/lib/builtins/CMakeLists.txt
@@ -695,6 +695,8 @@
     append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
+  append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS)
+
   append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
 
   # These flags would normally be added to CMAKE_C_FLAGS by the llvm
diff --git a/lib/builtins/extendhftf2.c b/lib/builtins/extendhftf2.c
index 196f8c9..aefe973 100644
--- a/lib/builtins/extendhftf2.c
+++ b/lib/builtins/extendhftf2.c
@@ -11,7 +11,7 @@
 #include "fp_lib.h"
 
 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) &&                     \
-    defined(CRT_HAS_FLOAT16)
+    defined(COMPILER_RT_HAS_FLOAT16)
 #define SRC_HALF
 #define DST_QUAD
 #include "fp_extend_impl.inc"
diff --git a/lib/builtins/fp_extend.h b/lib/builtins/fp_extend.h
index 7ba89f7..eee4722 100644
--- a/lib/builtins/fp_extend.h
+++ b/lib/builtins/fp_extend.h
@@ -40,7 +40,7 @@
 }
 
 #elif defined SRC_HALF
-#ifdef CRT_HAS_FLOAT16
+#ifdef COMPILER_RT_HAS_FLOAT16
 typedef _Float16 src_t;
 #else
 typedef uint16_t src_t;
diff --git a/lib/builtins/fp_trunc.h b/lib/builtins/fp_trunc.h
index b92acd8..7a54564 100644
--- a/lib/builtins/fp_trunc.h
+++ b/lib/builtins/fp_trunc.h
@@ -50,7 +50,7 @@
 static const int dstSigBits = 23;
 
 #elif defined DST_HALF
-#ifdef CRT_HAS_FLOAT16
+#ifdef COMPILER_RT_HAS_FLOAT16
 typedef _Float16 dst_t;
 #else
 typedef uint16_t dst_t;
diff --git a/lib/builtins/int_types.h b/lib/builtins/int_types.h
index 8bbdab5..9ee5a32 100644
--- a/lib/builtins/int_types.h
+++ b/lib/builtins/int_types.h
@@ -165,10 +165,6 @@
 #define HAS_80_BIT_LONG_DOUBLE 0
 #endif
 
-#ifdef __FLT16_MAX__
-#define CRT_HAS_FLOAT16
-#endif
-
 #if CRT_HAS_FLOATING_POINT
 typedef union {
   uqwords u;
diff --git a/lib/builtins/trunctfhf2.c b/lib/builtins/trunctfhf2.c
index b66b435..e3a2309 100644
--- a/lib/builtins/trunctfhf2.c
+++ b/lib/builtins/trunctfhf2.c
@@ -11,7 +11,7 @@
 #include "fp_lib.h"
 
 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) &&                     \
-    defined(CRT_HAS_FLOAT16)
+    defined(COMPILER_RT_HAS_FLOAT16)
 #define SRC_QUAD
 #define DST_HALF
 #include "fp_trunc_impl.inc"
diff --git a/test/builtins/CMakeLists.txt b/test/builtins/CMakeLists.txt
index 2a69f59..ceacbd8 100644
--- a/test/builtins/CMakeLists.txt
+++ b/test/builtins/CMakeLists.txt
@@ -44,6 +44,19 @@
     string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
   endif()
 
+  if(APPLE)
+    # TODO: Support the new ABI on Apple platforms.
+    if (${arch} MATCHES "arm|aarch64|arm64" AND COMPILER_RT_HAS_FLOAT16)
+      list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)
+      string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
+    endif()
+  else()
+    if (${arch} MATCHES "arm|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64" AND COMPILER_RT_HAS_FLOAT16)
+      list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)
+      string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
+    endif()
+  endif()
+
   if(COMPILER_RT_ENABLE_CET)
     if(NOT arch MATCHES "i?86|x86_64|AMD64")
       message(SEND_ERROR "${arch} does not support CET")
diff --git a/test/builtins/Unit/extendhftf2_test.c b/test/builtins/Unit/extendhftf2_test.c
index 43a5d44..7d3ea30 100644
--- a/test/builtins/Unit/extendhftf2_test.c
+++ b/test/builtins/Unit/extendhftf2_test.c
@@ -4,7 +4,7 @@
 #include "int_lib.h"
 #include <stdio.h>
 
-#if __LDBL_MANT_DIG__ == 113 && defined(CRT_HAS_FLOAT16)
+#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
 
 #include "fp_test.h"
 
@@ -28,7 +28,7 @@
 #endif
 
 int main() {
-#if __LDBL_MANT_DIG__ == 113 && defined(CRT_HAS_FLOAT16)
+#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
   // qNaN
   if (test__extendhftf2(makeQNaN16(),
                         UINT64_C(0x7fff800000000000),
diff --git a/test/builtins/Unit/fp_test.h b/test/builtins/Unit/fp_test.h
index 6fc80ac..e54dfc1 100644
--- a/test/builtins/Unit/fp_test.h
+++ b/test/builtins/Unit/fp_test.h
@@ -1,11 +1,10 @@
-#include "int_lib.h"
-#include <limits.h>
-#include <stdint.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <string.h>
+#include <stdint.h>
 
-#ifdef CRT_HAS_FLOAT16
-#  define TYPE_FP16 _Float16
+#ifdef COMPILER_RT_HAS_FLOAT16
+#define TYPE_FP16 _Float16
 #else
 #define TYPE_FP16 uint16_t
 #endif
@@ -16,10 +15,10 @@
 
 static inline TYPE_FP16 fromRep16(uint16_t x)
 {
-#ifdef CRT_HAS_FLOAT16
-  TYPE_FP16 ret;
-  memcpy(&ret, &x, sizeof(ret));
-  return ret;
+#ifdef COMPILER_RT_HAS_FLOAT16
+    TYPE_FP16 ret;
+    memcpy(&ret, &x, sizeof(ret));
+    return ret;
 #else
     return x;
 #endif
@@ -51,7 +50,7 @@
 
 static inline uint16_t toRep16(TYPE_FP16 x)
 {
-#ifdef CRT_HAS_FLOAT16
+#ifdef COMPILER_RT_HAS_FLOAT16
     uint16_t ret;
     memcpy(&ret, &x, sizeof(ret));
     return ret;
diff --git a/test/builtins/Unit/trunctfhf2_test.c b/test/builtins/Unit/trunctfhf2_test.c
index e4489d2..9c8c4af 100644
--- a/test/builtins/Unit/trunctfhf2_test.c
+++ b/test/builtins/Unit/trunctfhf2_test.c
@@ -4,7 +4,7 @@
 #include "int_lib.h"
 #include <stdio.h>
 
-#if __LDBL_MANT_DIG__ == 113 && defined(CRT_HAS_FLOAT16)
+#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
 
 #include "fp_test.h"
 
@@ -27,7 +27,7 @@
 #endif
 
 int main() {
-#if __LDBL_MANT_DIG__ == 113 && defined(CRT_HAS_FLOAT16)
+#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
   // qNaN
   if (test__trunctfhf2(makeQNaN128(),
                        UINT16_C(0x7e00)))