[mlir][LLVM] Verify correct pointer casts with `llvm.bitcast`
authorMarkus Böck <markus.boeck02@gmail.com>
Sun, 12 Feb 2023 22:55:47 +0000 (23:55 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Mon, 13 Feb 2023 21:24:20 +0000 (22:24 +0100)
commit009fc4ca3b4476826c89de05cb74d0afe2b5d609
treec6baa81318e48b45d49b7178182f18e8589ed74e
parent0aaf2e3bc057aa1d784455f8f4da66bc464733d6
[mlir][LLVM] Verify correct pointer casts with `llvm.bitcast`

`llvm.bitcast` has so far not had a verifier and this allowed various bugs to sneak into the codebase (including within tests!) which could only be caught once translated to actual LLVM IR. This patch fixes those problematic cases by now verifying bitcasts on pointers are done correctly.

Specifically, it verifies that if pointers are involved, that both result and source types are pointers, that this also applies to vector of pointers and that pointer casts are of the same address space.

The only thing left unverified is the general case of "source type size does not match result type size". I think this case is less trivial and more prone to false positives, so I did not yet implement it.

Differential Revision: https://reviews.llvm.org/D143868
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/test/Dialect/LLVMIR/invalid.mlir