Skip to content

[support] Add packed_endian_specific_integral::value() #147974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

labath
Copy link
Collaborator

@labath labath commented Jul 10, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

@llvm/pr-subscribers-llvm-support

Author: Pavel Labath (labath)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/147974.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Support/Endian.h (+2-1)
  • (modified) llvm/lib/ExecutionEngine/JITLink/aarch32.cpp (+3-4)
diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h
index 574f9508420a0..02a3194e09784 100644
--- a/llvm/include/llvm/Support/Endian.h
+++ b/llvm/include/llvm/Support/Endian.h
@@ -223,10 +223,11 @@ struct packed_endian_specific_integral {
 
   explicit packed_endian_specific_integral(value_type val) { *this = val; }
 
-  operator value_type() const {
+  value_type value() const {
     return endian::read<value_type, endian, alignment>(
       (const void*)Value.buffer);
   }
+  operator value_type() const { return value(); }
 
   void operator=(value_type newValue) {
     endian::write<value_type, endian, alignment>(
diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
index 1e325d76bd515..12d31f809f882 100644
--- a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
@@ -239,15 +239,14 @@ Error makeUnexpectedOpcodeError(const LinkGraph &G, const ThumbRelocation &R,
                                 Edge::Kind Kind) {
   return make_error<JITLinkError>(
       formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
-              static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
-              G.getEdgeKindName(Kind)));
+              R.Hi.value(), R.Lo.value(), G.getEdgeKindName(Kind)));
 }
 
 Error makeUnexpectedOpcodeError(const LinkGraph &G, const ArmRelocation &R,
                                 Edge::Kind Kind) {
   return make_error<JITLinkError>(
-      formatv("Invalid opcode {0:x8} for relocation: {1}",
-              static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind)));
+      formatv("Invalid opcode {0:x8} for relocation: {1}", R.Wd.value(),
+              G.getEdgeKindName(Kind)));
 }
 
 template <EdgeKind_aarch32 K> constexpr bool isArm() {

@dwblaikie
Copy link
Collaborator

I guess there's already unit test coverage for Endian - could extend it to cover the new function?

@labath
Copy link
Collaborator Author

labath commented Jul 10, 2025

There isn't much in the obvious place, but sure, I can add something there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants