[llvm] [GISel] Enforce G_PTR_ADD RHS type matching index size for addr space (PR #84352)

Pierre van Houtryve via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 05:39:08 PST 2024


================
@@ -1301,6 +1301,15 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
     if (OffsetTy.isPointerOrPointerVector())
       report("gep offset operand must not be a pointer", MI);
 
+    if (PtrTy.isPointerOrPointerVector()) {
+      const DataLayout &DL = MF->getDataLayout();
+      unsigned AS = PtrTy.getAddressSpace();
+      unsigned IndexSizeInBits = DL.getIndexSize(AS) * 8;
+      if (OffsetTy.getScalarSizeInBits() != IndexSizeInBits)
+        report("gep offset operand must match index size for address space",
+               MI);
----------------
Pierre-vh wrote:

Use braces as this takes 2 lines even if it's one stmt

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


More information about the llvm-commits mailing list