[compiler-rt] [compiler-rt][x86] Don't use assert.h when building without a libc (PR #165384)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 05:49:36 PDT 2025


https://github.com/quic-k created https://github.com/llvm/llvm-project/pull/165384

fixes https://github.com/llvm/llvm-project/issues/164932

>From b38321cb8f912767464e0aeda882798fcbe6eeaf Mon Sep 17 00:00:00 2001
From: Kushal Pal <kushpal at qti.qualcomm.com>
Date: Fri, 24 Oct 2025 11:22:01 +0530
Subject: [PATCH] [compiler-rt][x86] Don't use assert.h when building without a
 libc

Signed-off-by: Kushal Pal <kushpal at qti.qualcomm.com>
---
 compiler-rt/lib/builtins/cpu_model/x86.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index c21b2bad1d212..f4851ae11ff90 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -21,7 +21,9 @@
 
 #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
 
+#if defined(__linux__) && __STDC_HOSTED__
 #include <assert.h>
+#endif // defined(__linux__) && __STDC_HOSTED__
 
 #if (defined(__GNUC__) || defined(__clang__)) && !defined(_MSC_VER)
 #include <cpuid.h>
@@ -245,7 +247,7 @@ struct __processor_model {
   unsigned int __cpu_features[1];
 } __cpu_model = {0, 0, 0, {0}};
 
-static_assert(sizeof(__cpu_model) == 16,
+_Static_assert(sizeof(__cpu_model) == 16,
               "Wrong size of __cpu_model will result in ABI break");
 
 // This code is copied from lib/Support/Host.cpp.
@@ -1200,8 +1202,8 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
   unsigned Vendor;
   unsigned Model, Family;
   unsigned Features[(CPU_FEATURE_MAX + 31) / 32] = {0};
-  static_assert(sizeof(Features) / sizeof(Features[0]) == 4, "");
-  static_assert(sizeof(__cpu_features2) / sizeof(__cpu_features2[0]) == 3, "");
+  _Static_assert(sizeof(Features) / sizeof(Features[0]) == 4, "");
+  _Static_assert(sizeof(__cpu_features2) / sizeof(__cpu_features2[0]) == 3, "");
 
   // This function needs to run just once.
   if (__cpu_model.__cpu_vendor)
@@ -1234,9 +1236,11 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
   } else
     __cpu_model.__cpu_vendor = VENDOR_OTHER;
 
+#if defined(__linux__) && __STDC_HOSTED__
   assert(__cpu_model.__cpu_vendor < VENDOR_MAX);
   assert(__cpu_model.__cpu_type < CPU_TYPE_MAX);
   assert(__cpu_model.__cpu_subtype < CPU_SUBTYPE_MAX);
+#endif // defined(__linux__) && __STDC_HOSTED__
 
   return 0;
 }



More information about the llvm-commits mailing list