[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:53:46 PDT 2025
https://github.com/quic-k updated https://github.com/llvm/llvm-project/pull/165384
>From 57ab60b6f12de1dd81f8c24fb2c6718947c1ade9 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 | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index c21b2bad1d212..352bcc1da630c 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,8 +247,8 @@ struct __processor_model {
unsigned int __cpu_features[1];
} __cpu_model = {0, 0, 0, {0}};
-static_assert(sizeof(__cpu_model) == 16,
- "Wrong size of __cpu_model will result in ABI break");
+_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.
// Changes to either file should be mirrored in the other.
@@ -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