[compiler-rt] [TySan] Fixed false positive when accessing offset member variables (PR #120406)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 03:40:42 PST 2024
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 95eb49a0905568a13c840b7866ce5d9c47e022f0 4d70fda2f8047cb7145776be78b9caf260ea67cf --extensions cpp,c -- compiler-rt/test/tysan/global-struct-members.c 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 8595d9014d..d8aee2278c 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -227,20 +227,21 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
int i = -((sptr)OldTD);
OldTDPtr -= i;
OldTD = *OldTDPtr;
-
+
tysan_type_descriptor *AccessedType = OldTD;
-
+
// Only check if we are accessing members if the type exists
- if(OldTD != nullptr){
- // When shadow memory is set for global objects, the entire object is tagged
- // with the struct type This means that when you access a member variable,
- // tysan reads that as you accessing a struct midway through, with 'i' being
- // the offset Therefore, if you are accessing a struct, we need to find the
- // member type. We can go through the members of the struct type and see if
- // there is a member at the offset you are accessing the struct by. If there
- // is indeed a member starting at offset 'i' in the struct, we should check
- // aliasing legality with that type. If there isn't, we run alias checking
- // on the struct which will give us the correct error.
+ if (OldTD != nullptr) {
+ // When shadow memory is set for global objects, the entire object is
+ // tagged with the struct type This means that when you access a member
+ // variable, tysan reads that as you accessing a struct midway through,
+ // with 'i' being the offset Therefore, if you are accessing a struct, we
+ // need to find the member type. We can go through the members of the
+ // struct type and see if there is a member at the offset you are
+ // accessing the struct by. If there is indeed a member starting at offset
+ // 'i' in the struct, we should check aliasing legality with that type. If
+ // there isn't, we run alias checking on the struct which will give us the
+ // correct error.
if (OldTD->Tag == TYSAN_STRUCT_TD) {
for (int j = 0; j < OldTD->Struct.MemberCount; ++j) {
if (OldTD->Struct.Members[j].Offset == i) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/120406
More information about the llvm-commits
mailing list