[llvm] Extra assertions in RS4GC (PR #71201)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 09:40:12 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Petr Maj (zduka)

<details>
<summary>Changes</summary>

Adds assertion that the base/derived pointers are of the same size. 



---
Full diff: https://github.com/llvm/llvm-project/pull/71201.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+7) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 63ee11295e9c032..35945a8fb577545 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1249,6 +1249,8 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
 
 #ifndef NDEBUG
   VerifyStates();
+  // get the data layout to compare the sizes of base/derived pointer values
+  auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
 #endif
 
   // Cache all of our results so we can cheaply reuse them
@@ -1258,6 +1260,11 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
     auto *BDV = Pair.first;
     Value *Base = Pair.second.getBaseValue();
     assert(BDV && Base);
+    // the assumption is that whenever we have a derived ptr(s), their base
+    // ptr(s) must be of the same size, not necessarily the same type
+    assert(DL.getTypeAllocSize(BDV->getType()) ==
+               DL.getTypeAllocSize(Base->getType()) &&
+           "Derived and base values should have same size");
     // Only values that do not have known bases or those that have differing
     // type (scalar versus vector) from a possible known base should be in the
     // lattice.

``````````

</details>


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


More information about the llvm-commits mailing list