[compiler-rt] [TSan] Fix potentially problematic shadow end calculations (PR #144648)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 21 06:03:37 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,c,cpp -- compiler-rt/test/tsan/java_heap_init2.cpp compiler-rt/test/tsan/munmap_clear_shadow.c compiler-rt/lib/sanitizer_common/sanitizer_common.h compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/tsan/rtl/tsan_interface_java.cpp compiler-rt/lib/tsan/rtl/tsan_rtl.cpp compiler-rt/lib/tsan/rtl/tsan_rtl_access.cpp compiler-rt/lib/tsan/rtl/tsan_sync.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/test/tsan/java_heap_init2.cpp b/compiler-rt/test/tsan/java_heap_init2.cpp
index 09d2b5faf..241742dfe 100644
--- a/compiler-rt/test/tsan/java_heap_init2.cpp
+++ b/compiler-rt/test/tsan/java_heap_init2.cpp
@@ -10,16 +10,16 @@ int main() {
   size_t const kPageSize = sysconf(_SC_PAGESIZE);
   int const kSize = kPageSize - 1;
   jptr jheap2 = (jptr)mmap(0, kSize, PROT_READ | PROT_WRITE,
-      MAP_ANON | MAP_PRIVATE, -1, 0);
+                           MAP_ANON | MAP_PRIVATE, -1, 0);
   if (jheap2 == (jptr)MAP_FAILED)
     return printf("mmap failed with %d\n", errno);
-  __atomic_store_n((int*)(jheap2 + kSize - 3), 1, __ATOMIC_RELEASE);
+  __atomic_store_n((int *)(jheap2 + kSize - 3), 1, __ATOMIC_RELEASE);
   // Due to the previous incorrect meta-end calculation, the following munmap
   // did not clear the tail meta shadow.
-  munmap((void*)jheap2, kSize);
+  munmap((void *)jheap2, kSize);
   int const kHeapSize2 = kSize + 1;
-  jheap2 = (jptr)mmap((void*)jheap2, kHeapSize2, PROT_READ | PROT_WRITE,
-      MAP_ANON | MAP_PRIVATE, -1, 0);
+  jheap2 = (jptr)mmap((void *)jheap2, kHeapSize2, PROT_READ | PROT_WRITE,
+                      MAP_ANON | MAP_PRIVATE, -1, 0);
   if (jheap2 == (jptr)MAP_FAILED)
     return printf("second mmap failed with %d\n", errno);
   __tsan_java_init(jheap2, kHeapSize2);
diff --git a/compiler-rt/test/tsan/munmap_clear_shadow.c b/compiler-rt/test/tsan/munmap_clear_shadow.c
index b64a531d9..271e073f6 100644
--- a/compiler-rt/test/tsan/munmap_clear_shadow.c
+++ b/compiler-rt/test/tsan/munmap_clear_shadow.c
@@ -46,7 +46,7 @@ int main() {
   // If the shadow memory is cleared completely, the following read should not
   // cause a race.
   // CHECK-NOT: WARNING: ThreadSanitizer: data race
-  __tsan_read1(&buf[0]);       // Access 2
+  __tsan_read1(&buf[0]);        // Access 2
   __tsan_read1(&buf[Size - 1]); // Access 2
   pthread_join(t, 0);
 

``````````

</details>


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


More information about the llvm-commits mailing list