Hi all, these days when I use tir and try to construct some basic operations, I find that many operators will crash when receiving a NULL object.
To explore the root cause, I read its source code and find that TVM seems to assume all arguments of operators are valid in src/tir/op/op.cc. If we pass None as a parameter, it will be wrapped as an object whose data_
is equal to nullptr. And when we execute x.dtype()
, according to its code, it will try to access data_->dtype
, an illegal memory address since data_
points to nullptr.
// get() defined in ObjectRef
T* get() const { return static_cast<T*>(data_); }
// dtype() defined in PrimExpr
DataType dtype() const { return static_cast<const PrimExprNode*>(get())->dtype; }
To enhance the robustness and remind developers of their incorrect use, I think it’s necessary to raise an exception here instead of crashing the program. Is my idea correct?And if yes, how can we fix this unexpected behavior? I’d appreciate any help