Skip to content

Conversation

felipepiovezan
Copy link
Contributor

I've intentionally split this into two commits to make it easier that this is an NFC patch; don't think we need to preserve them separately though upon merging.

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2025

@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)

Changes

I've intentionally split this into two commits to make it easier that this is an NFC patch; don't think we need to preserve them separately though upon merging.


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

1 Files Affected:

  • (modified) lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp (+25-30)
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index 094e0523a4edf..16aafe640b1a4 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -757,42 +757,37 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(
   return return_valobj_sp;
 }
 
-addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
-  addr_t pac_sign_extension = 0x0080000000000000ULL;
-  addr_t tbi_mask = 0xff80000000000000ULL;
-  addr_t mask = 0;
-
-  if (ProcessSP process_sp = GetProcessSP()) {
-    mask = process_sp->GetCodeAddressMask();
-    if (pc & pac_sign_extension) {
-      addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
-      if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
-        mask = highmem_mask;
-    }
-  }
+constexpr addr_t tbi_mask = 0xff80000000000000ULL;
+constexpr addr_t pac_sign_extension = 0x0080000000000000ULL;
+
+static addr_t DoFixAddr(addr_t addr, bool is_code, ProcessSP process_sp) {
+  if (!process_sp)
+    return addr;
+
+  addr_t mask = is_code ? process_sp->GetCodeAddressMask()
+                        : process_sp->GetDataAddressMask();
   if (mask == LLDB_INVALID_ADDRESS_MASK)
     mask = tbi_mask;
 
-  return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
+  if (addr & pac_sign_extension) {
+    addr_t highmem_mask = is_code ? process_sp->GetHighmemCodeAddressMask()
+                                  : process_sp->GetHighmemCodeAddressMask();
+    if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
+      return addr | highmem_mask;
+    return addr | mask;
+  }
+
+  return addr & (~mask);
 }
 
-addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) {
-  addr_t pac_sign_extension = 0x0080000000000000ULL;
-  addr_t tbi_mask = 0xff80000000000000ULL;
-  addr_t mask = 0;
-
-  if (ProcessSP process_sp = GetProcessSP()) {
-    mask = process_sp->GetDataAddressMask();
-    if (pc & pac_sign_extension) {
-      addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
-      if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
-        mask = highmem_mask;
-    }
-  }
-  if (mask == LLDB_INVALID_ADDRESS_MASK)
-    mask = tbi_mask;
+addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
+  ProcessSP process_sp = GetProcessSP();
+  return DoFixAddr(pc, true /*is_code*/, GetProcessSP());
+}
 
-  return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
+addr_t ABIMacOSX_arm64::FixDataAddress(addr_t addr) {
+  ProcessSP process_sp = GetProcessSP();
+  return DoFixAddr(addr, false /*is_code*/, GetProcessSP());
 }
 
 void ABIMacOSX_arm64::Initialize() {

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, although we're not using tbi_mask anywhere now? We should probably remove it if it's not being used.

@felipepiovezan
Copy link
Contributor Author

This looks fine, although we're not using tbi_mask anywhere now? We should probably remove it if it's not being used.

It is!

  if (mask == LLDB_INVALID_ADDRESS_MASK)
    mask = tbi_mask;

@felipepiovezan felipepiovezan merged commit a666286 into llvm:main Sep 18, 2025
9 checks passed
@felipepiovezan felipepiovezan deleted the felipe/simplify_logic_fixdata branch September 18, 2025 20:52
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Sep 18, 2025
…59612)

I've intentionally split this into two commits to make it easier that
this is an NFC patch; don't think we need to preserve them separately
though upon merging.

(cherry picked from commit a666286)
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Sep 19, 2025
…59612)

I've intentionally split this into two commits to make it easier that
this is an NFC patch; don't think we need to preserve them separately
though upon merging.

(cherry picked from commit a666286)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants