Fix tagged pointer support
[deliverable/binutils-gdb.git] / gdb / utils.c
index 63929b2a54c3d6b4f9331f4de5046d37143d57b3..9c5bf68e5aaf2d038d94738f9e26b82b79d9d4df 100644 (file)
@@ -2705,14 +2705,18 @@ When set, debugging messages will be marked with seconds and microseconds."),
 CORE_ADDR
 address_significant (gdbarch *gdbarch, CORE_ADDR addr)
 {
-  /* Truncate address to the significant bits of a target address,
-     avoiding shifts larger or equal than the width of a CORE_ADDR.
-     The local variable ADDR_BIT stops the compiler reporting a shift
-     overflow when it won't occur.  */
+  /* Clear insignificant bits of a target address and sign extend resulting
+     address, avoiding shifts larger or equal than the width of a CORE_ADDR.
+     The local variable ADDR_BIT stops the compiler reporting a shift overflow
+     when it won't occur.  */
   int addr_bit = gdbarch_significant_addr_bit (gdbarch);
 
   if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
-    addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+    {
+      CORE_ADDR sign = (CORE_ADDR) 1 << (addr_bit - 1);
+      addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+      addr = (addr ^ sign) - sign;
+    }
 
   return addr;
 }
This page took 0.02411 seconds and 4 git commands to generate.