tvm
tvm copied to clipboard
[TIR] Fix segfaults from ordering of Let/Assert in MakePackedAPI
Prior to this commit, the MakePackedAPI pass would output steps in the following order:
- Check the number of arguments.
- All
LetStmtproduced by theArgBinder AssertStmtfor the Type code checks for each argument.- Additional
AssertStmtproduced by theArgBinder.
This order can cause segfaults if a function was provided incorrect arguments. For example, an integer argument passed to a function expecting a DLTensor* would be dereferenced to find the tensor's data pointer (step (2)) before checking if it is valid to perform that dereference (step (3)). The same would occur when reading the size of a tensor's axes (step (2)) before checking whether the tensor is the correct dimensionality (step (4)).
This commit updates the steps to the following order.
- Check the number of arguments.
- Check the type code of each argument.
- All
LetStmtandAssertStmtproduced by theArgBinder, in the order in which they are generated.
This came about while debugging the implementation of https://github.com/apache/tvm/pull/16542, but is otherwise unrelated.
Merged from main to PR branch, to resolve CI breakage that was fixed in https://github.com/apache/tvm/pull/16546.
Last CI failure is due to a flaky hexagon test. I've added a @pytest.mark.skip to this PR, now just waiting on CI.