[compiler-rt] [TySan] Fix struct access with different bases (PR #120412)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 09:28:22 PST 2025


================
@@ -131,6 +131,14 @@ static bool isAliasingLegalUp(tysan_type_descriptor *TDA,
           break;
       }
 
+      // This offset can't be negative. Therefore we must be accessing something
+      // partially inside the last type
+      // We shouldn't check this if we are on the first member, Idx will
+      // underflow, The first member can be offset in rare cases such as
+      // llvm::cl::Option.
+      if (TDA->Struct.Members[Idx].Offset > OffsetA && Idx > 0)
+        Idx -= 1;
----------------
fhahn wrote:

```suggestion
      if (TDA->Struct.Members[Idx].Offset > OffsetA) {
         // Trying to access something before the current type.
         if (!Idx)
           return false;
           
         Idx -= 1;
      }
```

I think if `Idx == 0`, we would be trying to access something before the current type, which shouldn't be valid?

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


More information about the llvm-commits mailing list