diff options
| author | Alex Zinenko <zinenko@google.com> | 2019-10-11 06:22:40 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-11 06:33:26 -0700 |
| commit | 8c2ea320728a381c8b7441990bc9929ff22fae5f (patch) | |
| tree | 5e7e4ba855dcaa0ced10cf9fdaa2f5071db55b89 /mlir/test/Examples/Toy | |
| parent | 71b82bcbf653fff62bf350991eb23fccd8796531 (diff) | |
| download | bcm5719-llvm-8c2ea320728a381c8b7441990bc9929ff22fae5f.tar.gz bcm5719-llvm-8c2ea320728a381c8b7441990bc9929ff22fae5f.zip | |
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
Diffstat (limited to 'mlir/test/Examples/Toy')
| -rw-r--r-- | mlir/test/Examples/Toy/Ch5/lowering.toy | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/mlir/test/Examples/Toy/Ch5/lowering.toy b/mlir/test/Examples/Toy/Ch5/lowering.toy index 3c198a6479f..6f16437e901 100644 --- a/mlir/test/Examples/Toy/Ch5/lowering.toy +++ b/mlir/test/Examples/Toy/Ch5/lowering.toy @@ -6,7 +6,7 @@ def multiply_transpose(a, b) { } # CHECK: define void @main() { -# CHECK: %1 = call i8* @malloc(i64 48) +# CHECK: %1 = call i8* @malloc(i64 mul (i64 ptrtoint (double* getelementptr (double, double* null, i64 1) to i64), i64 6)) def main() { var a<2, 3> = [[1, 2, 3], [4, 5, 6]]; var b<2, 3> = [1, 2, 3, 4, 5, 6]; |

