[Lldb-commits] [llvm] [lldb] [compiler-rt] [libcxx] [clang] [mlir] [lld] [clang-tools-extra] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)

Thurston Dang via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 13 09:04:57 PST 2023


================
@@ -0,0 +1,24 @@
+// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <memory>
+#include <sanitizer/hwasan_interface.h>
+#include <set>
+#include <stdio.h>
+
+int main() {
+  auto p = std::make_unique<char>();
+  std::set<void *> ptrs;
+  for (unsigned i = 0;; ++i) {
+    void *ptr = __hwasan_tag_pointer(p.get(), i);
+    if (!ptrs.insert(ptr).second)
+      break;
+    fprintf(stderr, "%p, %u, %u\n", ptr, i, __hwasan_get_tag_from_pointer(ptr));
+    assert(__hwasan_get_tag_from_pointer(ptr) == i);
+  }
+#ifdef __x86_64__
+  assert(ptrs.size() == 8);
----------------
thurstond wrote:

Is this assuming aliasing mode with 3-bit tags? If so, can the assumption be added to a `// REQUIRES` or similar?

https://github.com/llvm/llvm-project/pull/75267


More information about the lldb-commits mailing list