[compiler-rt] [TySan] Fix false positives with derived classes (PR #126260)

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 08:40:38 PST 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 025541ddedd23e39d9394ea8a1e41a64dfbe4e94 0a94da3186ae40a9a8999d4b3f8e0f47643fce42 --extensions cpp -- compiler-rt/test/tysan/derrived_default_constructor.cpp compiler-rt/test/tysan/inherited_member.cpp compiler-rt/lib/tysan/tysan.cpp
``````````

</details>

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

``````````diff
diff --git a/compiler-rt/lib/tysan/tysan.cpp b/compiler-rt/lib/tysan/tysan.cpp
index cf2b7d6bad..1c1580e193 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -102,10 +102,8 @@ static tysan_type_descriptor *getRootTD(tysan_type_descriptor *TD) {
   return RootTD;
 }
 
-bool walkAliasTree(
-  tysan_type_descriptor* TDA, tysan_type_descriptor* TDB,
-  uptr OffsetA, uptr OffsetB
-){
+bool walkAliasTree(tysan_type_descriptor *TDA, tysan_type_descriptor *TDB,
+                   uptr OffsetA, uptr OffsetB) {
   do {
     if (TDA == TDB)
       return OffsetA == OffsetB;
@@ -160,17 +158,19 @@ static bool isAliasingLegalUp(tysan_type_descriptor *TDA,
   return walkAliasTree(TDA, TDB, OffsetA, OffsetB);
 }
 
-static bool isAliasingLegalWithOffset(tysan_type_descriptor *AccessTD, tysan_type_descriptor *ShadowTD, int OffsetInShadow){
+static bool isAliasingLegalWithOffset(tysan_type_descriptor *AccessTD,
+                                      tysan_type_descriptor *ShadowTD,
+                                      int OffsetInShadow) {
   // This is handled in the other cases
-  if(OffsetInShadow == 0)
+  if (OffsetInShadow == 0)
     return false;
-  
+
   // You can't have an offset into a member
-  if(ShadowTD->Tag == TYSAN_MEMBER_TD)
+  if (ShadowTD->Tag == TYSAN_MEMBER_TD)
     return false;
 
   int OffsetInAccess = 0;
-  if(AccessTD->Tag == TYSAN_MEMBER_TD){
+  if (AccessTD->Tag == TYSAN_MEMBER_TD) {
     OffsetInAccess = AccessTD->Member.Offset;
     AccessTD = AccessTD->Member.Base;
   }
diff --git a/compiler-rt/test/tysan/derrived_default_constructor.cpp b/compiler-rt/test/tysan/derrived_default_constructor.cpp
index b232d79493..39705bfbb3 100644
--- a/compiler-rt/test/tysan/derrived_default_constructor.cpp
+++ b/compiler-rt/test/tysan/derrived_default_constructor.cpp
@@ -2,26 +2,24 @@
 
 #include <stdio.h>
 
-class Inner{
+class Inner {
 public:
-    void* ptr = nullptr;
+  void *ptr = nullptr;
 };
 
-class Base{
+class Base {
 public:
-    void* buffer1;
-    Inner inside;
-    void* buffer2;
+  void *buffer1;
+  Inner inside;
+  void *buffer2;
 };
 
-class Derrived : public Base{
-
-};
+class Derrived : public Base {};
 
 Derrived derr;
 
-int main(){
-    printf("%p", derr.inside.ptr);
+int main() {
+  printf("%p", derr.inside.ptr);
 
-    return 0;
+  return 0;
 }
diff --git a/compiler-rt/test/tysan/inherited_member.cpp b/compiler-rt/test/tysan/inherited_member.cpp
index 9a96f6f400..f23d69e6c8 100644
--- a/compiler-rt/test/tysan/inherited_member.cpp
+++ b/compiler-rt/test/tysan/inherited_member.cpp
@@ -2,22 +2,20 @@
 
 #include <stdio.h>
 
-class Base{
+class Base {
 public:
-    void* first;
-    void* second;
-    void* third;
+  void *first;
+  void *second;
+  void *third;
 };
 
-class Derrived : public Base{
-
-};
+class Derrived : public Base {};
 
 Derrived derr;
 
-int main(){
-    derr.second = nullptr;
-    printf("%p", derr.second);
+int main() {
+  derr.second = nullptr;
+  printf("%p", derr.second);
 
-    return 0;
+  return 0;
 }

``````````

</details>


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


More information about the llvm-commits mailing list