Skip to content

Commit a3a99c3

Browse files
quic-kcompnerd
andauthored
[compiler-rt][x86] Don't use assert.h when building without a libc (#165384)
fixes #164932 Signed-off-by: Kushal Pal <[email protected]> Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent 00ee53c commit a3a99c3

File tree

1 file changed

+8
-4
lines changed
  • compiler-rt/lib/builtins/cpu_model

1 file changed

+8
-4
lines changed

compiler-rt/lib/builtins/cpu_model/x86.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
2323

24+
#if __STDC_HOSTED__
2425
#include <assert.h>
26+
#endif // __STDC_HOSTED__
2527

2628
#if (defined(__GNUC__) || defined(__clang__)) && !defined(_MSC_VER)
2729
#include <cpuid.h>
@@ -245,8 +247,8 @@ struct __processor_model {
245247
unsigned int __cpu_features[1];
246248
} __cpu_model = {0, 0, 0, {0}};
247249

248-
static_assert(sizeof(__cpu_model) == 16,
249-
"Wrong size of __cpu_model will result in ABI break");
250+
_Static_assert(sizeof(__cpu_model) == 16,
251+
"Wrong size of __cpu_model will result in ABI break");
250252

251253
// This code is copied from lib/Support/Host.cpp.
252254
// Changes to either file should be mirrored in the other.
@@ -1200,8 +1202,8 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
12001202
unsigned Vendor;
12011203
unsigned Model, Family;
12021204
unsigned Features[(CPU_FEATURE_MAX + 31) / 32] = {0};
1203-
static_assert(sizeof(Features) / sizeof(Features[0]) == 4, "");
1204-
static_assert(sizeof(__cpu_features2) / sizeof(__cpu_features2[0]) == 3, "");
1205+
_Static_assert(sizeof(Features) / sizeof(Features[0]) == 4, "");
1206+
_Static_assert(sizeof(__cpu_features2) / sizeof(__cpu_features2[0]) == 3, "");
12051207

12061208
// This function needs to run just once.
12071209
if (__cpu_model.__cpu_vendor)
@@ -1234,9 +1236,11 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
12341236
} else
12351237
__cpu_model.__cpu_vendor = VENDOR_OTHER;
12361238

1239+
#if __STDC_HOSTED__
12371240
assert(__cpu_model.__cpu_vendor < VENDOR_MAX);
12381241
assert(__cpu_model.__cpu_type < CPU_TYPE_MAX);
12391242
assert(__cpu_model.__cpu_subtype < CPU_SUBTYPE_MAX);
1243+
#endif // __STDC_HOSTED__
12401244

12411245
return 0;
12421246
}

0 commit comments

Comments
 (0)