[Mlir-commits] [mlir] ae461d8 - [MLIR][Bytecode] Ensure `dataIt` is aligned coming out of `EncodingReader::alignTo`.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Nov 13 09:27:29 PST 2022


Author: bzcheeseman
Date: 2022-11-13T09:27:23-08:00
New Revision: ae461d8b99e63e26726ce3047f00b78180d427d8

URL: https://github.com/llvm/llvm-project/commit/ae461d8b99e63e26726ce3047f00b78180d427d8
DIFF: https://github.com/llvm/llvm-project/commit/ae461d8b99e63e26726ce3047f00b78180d427d8.diff

LOG: [MLIR][Bytecode] Ensure `dataIt` is aligned coming out of `EncodingReader::alignTo`.

This addresses the TODO in the code previously and checks that the address of `dataIt` is properly aligned to the requested alignment.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D137855

Added: 
    

Modified: 
    mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index 8224729b6bd13..4ea8759615fcb 100644
--- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -103,8 +103,13 @@ class EncodingReader {
       }
     }
 
-    // TODO: Check that the current data pointer is actually at the expected
-    // alignment.
+    // Ensure the data iterator is now aligned. This case is unlikely because we
+    // *just* went through the effort to align the data iterator.
+    if (LLVM_UNLIKELY(!llvm::isAddrAligned(llvm::Align(alignment), dataIt))) {
+      return emitError("expected data iterator aligned to ", alignment,
+                       ", but got pointer: '0x" +
+                           llvm::utohexstr((uintptr_t)dataIt) + "'");
+    }
 
     return success();
   }


        


More information about the Mlir-commits mailing list