llvm-project/mlir/test/Examples
Alex Zinenko 8c2ea32072 Emit LLVM IR equivalent of sizeof when lowering alloc operations
Originally, the lowering of `alloc` operations has been computing the number of
bytes to allocate when lowering based on the properties of MLIR type. This does
not take into account type legalization that happens when compiling LLVM IR
down to target assembly. This legalization can widen the type, potentially
leading to out-of-bounds accesses to `alloc`ed data due to mismatches between
address computation that takes the widening into account and allocation that
does not. Use the LLVM IR's equivalent of `sizeof` to compute the number of
bytes to be allocated:
  %0 = getelementptr %type* null, %indexType 0
  %1 = ptrtoint %type* %0 to %indexType
adapted from
http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt

PiperOrigin-RevId: 274159900
2019-10-11 06:33:26 -07:00
..
Linalg Normalize MemRefType lowering to LLVM as strided MemRef descriptor 2019-09-30 11:58:54 -07:00
Toy Emit LLVM IR equivalent of sizeof when lowering alloc operations 2019-10-11 06:33:26 -07:00
lit.local.cfg Initial version for chapter 1 of the Toy tutorial 2019-04-02 13:40:06 -07:00