[compiler-rt] c13ac9c - [Compiler-rt] Fix wrong assignment in compiler_rt (#164713)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 09:04:46 PDT 2025
Author: Mikołaj Piróg
Date: 2025-10-23T16:04:41Z
New Revision: c13ac9cadf1f9b4fa886b82d1e84a5feb0439023
URL: https://github.com/llvm/llvm-project/commit/c13ac9cadf1f9b4fa886b82d1e84a5feb0439023
DIFF: https://github.com/llvm/llvm-project/commit/c13ac9cadf1f9b4fa886b82d1e84a5feb0439023.diff
LOG: [Compiler-rt] Fix wrong assignment in compiler_rt (#164713)
The `INTEL_CLEARWATERFOREST` belongs to `ProcessorTypes` enum, but it
was assigned to `Subtype` value, leading to cpu_specific/cpu_dispatch
not recognizing CWF. The type for `Subtype` and `Type` are changed to
respective enums to guard against these sort of errors in the future
Added:
Modified:
compiler-rt/lib/builtins/cpu_model/x86.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index 7ddfaa3e3ed6c..d9ff116cdc292 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -36,14 +36,14 @@ enum VendorSignatures {
SIG_AMD = 0x68747541, // Auth
};
-enum ProcessorVendors {
+enum ProcessorVendors : unsigned int {
VENDOR_INTEL = 1,
VENDOR_AMD,
VENDOR_OTHER,
VENDOR_MAX
};
-enum ProcessorTypes {
+enum ProcessorTypes : unsigned int {
INTEL_BONNELL = 1,
INTEL_CORE2,
INTEL_COREI7,
@@ -319,11 +319,9 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
-static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
- unsigned Model,
- const unsigned *Features,
- unsigned *Type,
- unsigned *Subtype) {
+static const char *getIntelProcessorTypeAndSubtype(
+ unsigned Family, unsigned Model, const unsigned *Features,
+ enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
// We select CPU strings to match the code in Host.cpp, but we don't use them
// in compiler-rt.
const char *CPU = 0;
@@ -616,8 +614,7 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
// Clearwaterforest:
case 0xdd:
CPU = "clearwaterforest";
- *Type = INTEL_COREI7;
- *Subtype = INTEL_CLEARWATERFOREST;
+ *Type = INTEL_CLEARWATERFOREST;
break;
case 0x57:
@@ -667,11 +664,9 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
return CPU;
}
-static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
- unsigned Model,
- const unsigned *Features,
- unsigned *Type,
- unsigned *Subtype) {
+static const char *getAMDProcessorTypeAndSubtype(
+ unsigned Family, unsigned Model, const unsigned *Features,
+ enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
const char *CPU = 0;
switch (Family) {
@@ -1162,11 +1157,14 @@ __attribute__((visibility("hidden")))
#endif
struct __processor_model {
unsigned int __cpu_vendor;
- unsigned int __cpu_type;
- unsigned int __cpu_subtype;
+ enum ProcessorTypes __cpu_type;
+ enum ProcessorSubtypes __cpu_subtype;
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");
+
#ifndef _WIN32
__attribute__((visibility("hidden")))
#endif
More information about the llvm-commits
mailing list