Skip to content

Commit 7694856

Browse files
authored
Fix TargetParserTests for big-endian hosts (#152407)
The new `sys::detail::getHostCPUNameForARM` for Windows (#151596) was implemented using a C++ bit-field, which caused the associated unit tests to fail on big-endian machines as it assumed a little-endian layout. This change switches from the C++ bit-field to LLVM's `BitField` type instead.
1 parent acb5d0c commit 7694856

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

llvm/lib/TargetParser/Host.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/TargetParser/Host.h"
14+
#include "llvm/ADT/Bitfields.h"
1415
#include "llvm/ADT/STLFunctionalExtras.h"
1516
#include "llvm/ADT/SmallVector.h"
1617
#include "llvm/ADT/StringExtras.h"
@@ -434,22 +435,14 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) {
434435
StringRef sys::detail::getHostCPUNameForARM(uint64_t PrimaryCpuInfo,
435436
ArrayRef<uint64_t> UniqueCpuInfos) {
436437
// On Windows, the registry provides cached copied of the MIDR_EL1 register.
437-
union MIDR_EL1 {
438-
uint64_t Raw;
439-
struct _Components {
440-
uint64_t Revision : 4;
441-
uint64_t Partnum : 12;
442-
uint64_t Architecture : 4;
443-
uint64_t Variant : 4;
444-
uint64_t Implementer : 8;
445-
uint64_t Reserved : 32;
446-
} Components;
447-
};
438+
using PartNum = Bitfield::Element<uint16_t, 4, 12>;
439+
using Implementer = Bitfield::Element<uint16_t, 24, 8>;
440+
using Variant = Bitfield::Element<uint16_t, 20, 4>;
448441

449442
SmallVector<std::string> PartsHolder;
450443
PartsHolder.reserve(UniqueCpuInfos.size());
451444
for (auto Info : UniqueCpuInfos)
452-
PartsHolder.push_back("0x" + utohexstr(MIDR_EL1{Info}.Components.Partnum,
445+
PartsHolder.push_back("0x" + utohexstr(Bitfield::get<PartNum>(Info),
453446
/*LowerCase*/ true,
454447
/*Width*/ 3));
455448

@@ -459,14 +452,14 @@ StringRef sys::detail::getHostCPUNameForARM(uint64_t PrimaryCpuInfo,
459452
Parts.push_back(Part);
460453

461454
return getHostCPUNameForARMFromComponents(
462-
"0x" + utohexstr(MIDR_EL1{PrimaryCpuInfo}.Components.Implementer,
455+
"0x" + utohexstr(Bitfield::get<Implementer>(PrimaryCpuInfo),
463456
/*LowerCase*/ true,
464457
/*Width*/ 2),
465458
/*Hardware*/ "",
466-
"0x" + utohexstr(MIDR_EL1{PrimaryCpuInfo}.Components.Partnum,
459+
"0x" + utohexstr(Bitfield::get<PartNum>(PrimaryCpuInfo),
467460
/*LowerCase*/ true,
468461
/*Width*/ 3),
469-
Parts, [=]() { return MIDR_EL1{PrimaryCpuInfo}.Components.Variant; });
462+
Parts, [=]() { return Bitfield::get<Variant>(PrimaryCpuInfo); });
470463
}
471464

472465
namespace {

0 commit comments

Comments
 (0)