Skip to content

Commit c13ac9c

Browse files
[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
1 parent 6058c0c commit c13ac9c

File tree

1 file changed

+14
-16
lines changed
  • compiler-rt/lib/builtins/cpu_model

1 file changed

+14
-16
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ enum VendorSignatures {
3636
SIG_AMD = 0x68747541, // Auth
3737
};
3838

39-
enum ProcessorVendors {
39+
enum ProcessorVendors : unsigned int {
4040
VENDOR_INTEL = 1,
4141
VENDOR_AMD,
4242
VENDOR_OTHER,
4343
VENDOR_MAX
4444
};
4545

46-
enum ProcessorTypes {
46+
enum ProcessorTypes : unsigned int {
4747
INTEL_BONNELL = 1,
4848
INTEL_CORE2,
4949
INTEL_COREI7,
@@ -319,11 +319,9 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
319319

320320
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
321321

322-
static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
323-
unsigned Model,
324-
const unsigned *Features,
325-
unsigned *Type,
326-
unsigned *Subtype) {
322+
static const char *getIntelProcessorTypeAndSubtype(
323+
unsigned Family, unsigned Model, const unsigned *Features,
324+
enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
327325
// We select CPU strings to match the code in Host.cpp, but we don't use them
328326
// in compiler-rt.
329327
const char *CPU = 0;
@@ -616,8 +614,7 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
616614
// Clearwaterforest:
617615
case 0xdd:
618616
CPU = "clearwaterforest";
619-
*Type = INTEL_COREI7;
620-
*Subtype = INTEL_CLEARWATERFOREST;
617+
*Type = INTEL_CLEARWATERFOREST;
621618
break;
622619

623620
case 0x57:
@@ -667,11 +664,9 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
667664
return CPU;
668665
}
669666

670-
static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
671-
unsigned Model,
672-
const unsigned *Features,
673-
unsigned *Type,
674-
unsigned *Subtype) {
667+
static const char *getAMDProcessorTypeAndSubtype(
668+
unsigned Family, unsigned Model, const unsigned *Features,
669+
enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
675670
const char *CPU = 0;
676671

677672
switch (Family) {
@@ -1162,11 +1157,14 @@ __attribute__((visibility("hidden")))
11621157
#endif
11631158
struct __processor_model {
11641159
unsigned int __cpu_vendor;
1165-
unsigned int __cpu_type;
1166-
unsigned int __cpu_subtype;
1160+
enum ProcessorTypes __cpu_type;
1161+
enum ProcessorSubtypes __cpu_subtype;
11671162
unsigned int __cpu_features[1];
11681163
} __cpu_model = {0, 0, 0, {0}};
11691164

1165+
static_assert(sizeof(__cpu_model) == 16,
1166+
"Wrong size of __cpu_model will result in ABI break");
1167+
11701168
#ifndef _WIN32
11711169
__attribute__((visibility("hidden")))
11721170
#endif

0 commit comments

Comments
 (0)