tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[TIR] Fix segfaults from ordering of Let/Assert in MakePackedAPI

Open Lunderberg opened this issue 1 year ago • 2 comments

Prior to this commit, the MakePackedAPI pass would output steps in the following order:

  1. Check the number of arguments.
  2. All LetStmt produced by the ArgBinder
  3. AssertStmt for the Type code checks for each argument.
  4. Additional AssertStmt produced by the ArgBinder.

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.

  1. Check the number of arguments.
  2. Check the type code of each argument.
  3. All LetStmt and AssertStmt produced by the ArgBinder, in the order in which they are generated.

Lunderberg avatar Feb 08 '24 01:02 Lunderberg

This came about while debugging the implementation of https://github.com/apache/tvm/pull/16542, but is otherwise unrelated.

Lunderberg avatar Feb 08 '24 01:02 Lunderberg

Merged from main to PR branch, to resolve CI breakage that was fixed in https://github.com/apache/tvm/pull/16546.

Lunderberg avatar Feb 09 '24 20:02 Lunderberg

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.

Lunderberg avatar Apr 01 '24 18:04 Lunderberg