git: f4497535fe59 - 2022Q4 - devel/llvm1[2345]: fix build with clang 15

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Mon, 12 Dec 2022 17:38:20 UTC
The branch 2022Q4 has been updated by brooks:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f4497535fe59b5e0fee717a4c91032fc8bb223cc

commit f4497535fe59b5e0fee717a4c91032fc8bb223cc
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2022-12-12 17:37:59 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2022-12-12 17:37:59 +0000

    devel/llvm1[2345]: fix build with clang 15
    
    When building llvm12 through llvm15 with clang 15 as host compiler, and
    when compiler-rt is enabled, there will be errors due to float16
    support, similar to:
    
        In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/extendhfsf2.c:11:
        In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend_impl.inc:38:
        /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend.h:44:9: error: _Float16 is not supported on this target
        typedef _Float16 src_t;
                ^
    
    This is because compiler-rt's CMake infrastructure detects float16
    support at configure time, while targeting 'pure' x86_64, but then
    builds parts of its tree also targeting i386.
    
    To work around this, modify compiler-rt's top-level CMakeLists.txt to
    move setting the -DCOMPILER_RT_HAS_FLOAT16 compilation flag to the
    arch-specific for loop, so it only gets enabled for x86_64, and not for
    i386.
    
    For llvm15, also add another modification that removes the bfloat16
    source files from the i386_SOURCES list, so these are not built for
    i386.
    
    PR:             268196
    Submitted by:   dim
    (cherry picked from commit 830bbdd84a53aa33b48c01ee16048d1400094e26)
---
 .../patch-compiler-rt_lib_builtins_CMakeLists.txt  | 22 ++++++++++
 .../patch-compiler-rt_lib_builtins_CMakeLists.txt  | 22 ++++++++++
 .../patch-compiler-rt_lib_builtins_CMakeLists.txt  | 22 ++++++++++
 .../patch-compiler-rt_lib_builtins_CMakeLists.txt  | 50 ++++++++++++++++++++++
 4 files changed, 116 insertions(+)

diff --git a/devel/llvm12/files/patch-compiler-rt_lib_builtins_CMakeLists.txt b/devel/llvm12/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
new file mode 100644
index 000000000000..af02e8aa7dae
--- /dev/null
+++ b/devel/llvm12/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
@@ -0,0 +1,22 @@
+--- compiler-rt/lib/builtins/CMakeLists.txt.orig	2021-06-28 16:23:38 UTC
++++ compiler-rt/lib/builtins/CMakeLists.txt
+@@ -664,8 +664,6 @@ else ()
+ else ()
+   set(BUILTIN_CFLAGS "")
+ 
+-  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
+@@ -724,6 +722,10 @@ else ()
+       # double routines.
+       if("${arch}" STREQUAL "riscv32")
+         list(APPEND BUILTIN_CFLAGS -fforce-enable-int128)
++      endif()
++
++      if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND ${arch} STREQUAL "i386"))
++        append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})
+       endif()
+ 
+       add_compiler_rt_runtime(clang_rt.builtins
diff --git a/devel/llvm13/files/patch-compiler-rt_lib_builtins_CMakeLists.txt b/devel/llvm13/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
new file mode 100644
index 000000000000..874ad38b689a
--- /dev/null
+++ b/devel/llvm13/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
@@ -0,0 +1,22 @@
+--- compiler-rt/lib/builtins/CMakeLists.txt.orig	2022-01-20 21:31:59 UTC
++++ compiler-rt/lib/builtins/CMakeLists.txt
+@@ -675,8 +675,6 @@ else ()
+ else ()
+   set(BUILTIN_CFLAGS "")
+ 
+-  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
+@@ -747,6 +745,10 @@ else ()
+         )
+ 
+         set(deps_aarch64 lse_builtin_symlinks)
++      endif()
++
++      if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND ${arch} STREQUAL "i386"))
++        append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})
+       endif()
+ 
+       add_compiler_rt_runtime(clang_rt.builtins
diff --git a/devel/llvm14/files/patch-compiler-rt_lib_builtins_CMakeLists.txt b/devel/llvm14/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
new file mode 100644
index 000000000000..a1a022c059fc
--- /dev/null
+++ b/devel/llvm14/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
@@ -0,0 +1,22 @@
+--- compiler-rt/lib/builtins/CMakeLists.txt.orig	2022-06-22 16:46:24 UTC
++++ compiler-rt/lib/builtins/CMakeLists.txt
+@@ -682,8 +682,6 @@ else ()
+     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
+@@ -754,6 +752,10 @@ else ()
+         )
+ 
+         set(deps_aarch64 lse_builtin_symlinks)
++      endif()
++
++      if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND ${arch} STREQUAL "i386"))
++        append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})
+       endif()
+ 
+       add_compiler_rt_runtime(clang_rt.builtins
diff --git a/devel/llvm15/files/patch-compiler-rt_lib_builtins_CMakeLists.txt b/devel/llvm15/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
new file mode 100644
index 000000000000..e26ae7cf0634
--- /dev/null
+++ b/devel/llvm15/files/patch-compiler-rt_lib_builtins_CMakeLists.txt
@@ -0,0 +1,50 @@
+--- compiler-rt/lib/builtins/CMakeLists.txt.orig	2022-11-29 10:05:58 UTC
++++ compiler-rt/lib/builtins/CMakeLists.txt
+@@ -183,11 +183,14 @@ if(COMPILER_RT_HAS_BFLOAT16 AND NOT APPLE)
+ 
+ # Build BF16 files only when "__bf16" is available.
+ if(COMPILER_RT_HAS_BFLOAT16 AND NOT APPLE)
+-  set(GENERIC_SOURCES
+-    ${GENERIC_SOURCES}
++  set(GENERIC_BF_SOURCES
+     truncdfbf2.c
+     truncsfbf2.c
+   )
++  set(GENERIC_SOURCES
++    ${GENERIC_SOURCES}
++    ${GENERIC_BF_SOURCES}
++  )
+ endif()
+ 
+ # TODO: Several "tf" files (and divtc3.c, but not multc3.c) are in
+@@ -360,6 +363,10 @@ if (NOT MSVC)
+       i386/chkstk2.S
+     )
+   endif()
++
++  if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
++    list(REMOVE_ITEM i386_SOURCES ${GENERIC_BF_SOURCES})
++  endif()
+ else () # MSVC
+   # Use C versions of functions when building on MSVC
+   # MSVC's assembler takes Intel syntax, not AT&T syntax.
+@@ -703,8 +710,6 @@ else ()
+     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
+@@ -775,6 +780,10 @@ else ()
+         )
+ 
+         set(deps_aarch64 lse_builtin_symlinks)
++      endif()
++
++      if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND ${arch} STREQUAL "i386"))
++        append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS)
+       endif()
+ 
+       add_compiler_rt_runtime(clang_rt.builtins