Skip to content

Commit ba31b8c

Browse files
labathgithub-actions[bot]
authored andcommitted
Automerge: [support] Add packed_endian_specific_integral::value() (#147974)
They are already implicitly convertible to the underlying type, but that doesn't work in some contexts, and it can be useful to get the underlying value without needing the remember/guess the right type. I converted a couple of call sites to demonstrate usefulness, but there's likely more of them. I know at least of at least a few in LLDB, but I don't want to make this a cross-project patch.
2 parents 3898001 + 17784e8 commit ba31b8c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

llvm/include/llvm/Support/Endian.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ struct packed_endian_specific_integral {
223223

224224
explicit packed_endian_specific_integral(value_type val) { *this = val; }
225225

226-
operator value_type() const {
226+
value_type value() const {
227227
return endian::read<value_type, endian, alignment>(
228228
(const void*)Value.buffer);
229229
}
230+
operator value_type() const { return value(); }
230231

231232
void operator=(value_type newValue) {
232233
endian::write<value_type, endian, alignment>(

llvm/lib/ExecutionEngine/JITLink/aarch32.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,14 @@ Error makeUnexpectedOpcodeError(const LinkGraph &G, const ThumbRelocation &R,
239239
Edge::Kind Kind) {
240240
return make_error<JITLinkError>(
241241
formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
242-
static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
243-
G.getEdgeKindName(Kind)));
242+
R.Hi.value(), R.Lo.value(), G.getEdgeKindName(Kind)));
244243
}
245244

246245
Error makeUnexpectedOpcodeError(const LinkGraph &G, const ArmRelocation &R,
247246
Edge::Kind Kind) {
248247
return make_error<JITLinkError>(
249-
formatv("Invalid opcode {0:x8} for relocation: {1}",
250-
static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind)));
248+
formatv("Invalid opcode {0:x8} for relocation: {1}", R.Wd.value(),
249+
G.getEdgeKindName(Kind)));
251250
}
252251

253252
template <EdgeKind_aarch32 K> constexpr bool isArm() {

llvm/unittests/Support/EndianTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ TEST(Endian, PackedEndianSpecificIntegral) {
237237
reinterpret_cast<little32_t *>(little + 1);
238238

239239
EXPECT_EQ(*big_val, *little_val);
240+
EXPECT_EQ(big_val->value(), little_val->value());
240241
}
241242

242243
TEST(Endian, PacketEndianSpecificIntegralAsEnum) {

0 commit comments

Comments
 (0)