[llvm-branch-commits] [compiler-rt] [TySan] Fixed false positive when accessing offset member variables (PR #95387)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 2 09:21:02 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 8e6e62d0dee48a696afd0c7d53d74eaccef97b5e 8addd061964253a1100d76446569ff1f67e63a9c --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 228a5f13f5..da92e64181 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -226,20 +226,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/95387
More information about the llvm-branch-commits
mailing list