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

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


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

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


>From ee575f3f3b85bf89b00aa0cec3be85db68beeb8f Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Wed, 4 Dec 2024 16:08:37 +1300
Subject: [PATCH] VNCoercion: Safely handle targets where pointers are larger
 than the largest legal integers.

This does not impact any in-tree targets, but does impact CHERI targets.
---
 llvm/lib/Transforms/Utils/VNCoercion.cpp | 5 +++++
 1 file changed, 5 insertions(+)

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



More information about the llvm-commits mailing list