[Lldb-commits] [lldb] 3fd9c90 - [lldb][AArch64] Correct top nibble setting in memory tag read tests

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 12 04:28:56 PST 2022


Author: David Spickett
Date: 2022-01-12T12:28:13Z
New Revision: 3fd9c90bdc04df451d9bb348450b5ad424c822c6

URL: https://github.com/llvm/llvm-project/commit/3fd9c90bdc04df451d9bb348450b5ad424c822c6
DIFF: https://github.com/llvm/llvm-project/commit/3fd9c90bdc04df451d9bb348450b5ad424c822c6.diff

LOG: [lldb][AArch64] Correct top nibble setting in memory tag read tests

Due to a missing cast the << 60 always resulted in zero leaving
the top nibble empty. So we weren't actually testing that lldb
ignores those bits in addition to the tag bits.

Correct that and also set the top nibbles to ascending values
so that we can catch if lldb only removes one of the tag bits
and top nibble, but not both.

In future the tag manager will likely only remove the tag bits
and leave non-address bits to the ABI plugin but for now make
sure we're testing what we claim to implement.

Added: 
    

Modified: 
    lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
    lldb/test/API/linux/aarch64/mte_tag_access/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py b/lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
index b0ce9c1f55c44..29c19aa68fb72 100644
--- a/lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
+++ b/lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
@@ -122,10 +122,11 @@ def test_mte_tag_read(self):
                           "\[0x[0-9A-Fa-f]+f0, 0x[0-9A-Fa-f]+00\): 0xf \(mismatch\)\n"
                           "\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
 
-        # Tags in start/end are ignored when creating the range.
-        # So this is not an error despite start/end having 
diff erent tags
-        self.expect("memory tag read mte_buf mte_buf_alt_tag+16",
-                patterns=["Logical tag: 0x9\n"
+        # Top byte is ignored when creating the range, not just the 4 tag bits.
+        # So even though these two pointers have 
diff erent top bytes
+        # and the start's is > the end's, this is not an error.
+        self.expect("memory tag read mte_buf_alt_tag mte_buf+16",
+                patterns=["Logical tag: 0xa\n"
                           "Allocation tags:\n"
                           "\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
 

diff  --git a/lldb/test/API/linux/aarch64/mte_tag_access/main.c b/lldb/test/API/linux/aarch64/mte_tag_access/main.c
index ecafe3ae7bd34..493733d09562c 100644
--- a/lldb/test/API/linux/aarch64/mte_tag_access/main.c
+++ b/lldb/test/API/linux/aarch64/mte_tag_access/main.c
@@ -67,16 +67,20 @@ int main(int argc, char const *argv[]) {
 
   // Tag the original pointer with 9
   mte_buf = __arm_mte_create_random_tag(mte_buf, ~(1 << 9));
-  // A 
diff erent tag so that buf_alt_tag > buf if you don't handle the tag
+  // A 
diff erent tag so that mte_buf_alt_tag > mte_buf if you don't handle the
+  // tag
   char *mte_buf_alt_tag = __arm_mte_create_random_tag(mte_buf, ~(1 << 10));
 
   // lldb should be removing the whole top byte, not just the tags.
   // So fill 63-60 with something non zero so we'll fail if we only remove tags.
-#define SET_TOP_NIBBLE(ptr) (char *)((size_t)(ptr) | (0xA << 60))
-  mte_buf = SET_TOP_NIBBLE(mte_buf);
-  mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag);
-  mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2);
-  mte_read_only = SET_TOP_NIBBLE(mte_read_only);
+#define SET_TOP_NIBBLE(ptr, value)                                             \
+  (char *)((size_t)(ptr) | ((size_t)((value)&0xf) << 60))
+  // mte_buf_alt_tag's nibble > mte_buf to check that lldb isn't just removing
+  // tag bits but the whole top byte when making ranges.
+  mte_buf = SET_TOP_NIBBLE(mte_buf, 0xA);
+  mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag, 0xB);
+  mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2, 0xC);
+  mte_read_only = SET_TOP_NIBBLE(mte_read_only, 0xD);
 
   // Breakpoint here
   return 0;


        


More information about the lldb-commits mailing list