[llvm] VNCoercion: Safely handle targets where pointers are larger than the largest legal integers. (PR #118584)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 19:10:47 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Owen Anderson (resistor)

<details>
<summary>Changes</summary>

This does not impact any in-tree targets, but does impact CHERI targets.


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


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/VNCoercion.cpp (+5) 


``````````diff
diff --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp
index 1e0ae280516410..7fed5121831338 100644
--- a/llvm/lib/Transforms/Utils/VNCoercion.cpp
+++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp
@@ -248,6 +248,11 @@ int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
   ConstantInt *SizeCst = dyn_cast<ConstantInt>(MI->getLength());
   if (!SizeCst)
     return -1;
+  // If this is a pointer type that's larger than the largest integer that we
+  // support, then ignore it.
+  if (LoadTy->isPointerTy() &&
+      DL.getTypeSizeInBits(LoadTy) > DL.getLargestLegalIntTypeSizeInBits())
+    return -1;
   uint64_t MemSizeInBits = SizeCst->getZExtValue() * 8;
 
   // If this is memset, we just need to see if the offset is valid in the size

``````````

</details>


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


More information about the llvm-commits mailing list