Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/tvm/runtime/container/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ class Array : public ObjectRef {
*/
template <typename IterType>
Array(IterType first, IterType last) {
static_assert(is_valid_iterator_v<T, IterType>,
"IterType cannot be inserted into a tvm::Array<T>");
Assign(first, last);
}

Expand Down Expand Up @@ -481,6 +483,9 @@ class Array : public ObjectRef {
*/
template <typename IterType>
void insert(iterator position, IterType first, IterType last) {
static_assert(is_valid_iterator_v<T, IterType>,
"IterType cannot be inserted into a tvm::Array<T>");

if (first == last) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/te/schedule/schedule_lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Stage& Stage::env_threads(Array<IterVar> threads) {
ICHECK_EQ(self->env_threads.size(), 0U) << "Already set env_threads";
Array<IterVar>& leaf_vars = self->leaf_iter_vars;
Array<IterVar>& all_vars = self->all_iter_vars;
std::vector<ObjectRef> temp;
std::vector<IterVar> temp;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems unrelated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually the exact type of error that I wanted to catch with the static_assert statements. This was a std::vector<ObjectRef> which was copied into an Array<IterVar>, with no type-checking during the conversion. It didn't cause any runtime issues, because the std::vector was originally populated with ObjectRef instances that contain IterVarNode, but there were no compile-time checks to ensure that was the case. Had it been otherwise, the later use of ObjectRef::DowncastNoCheck<IterVar> would have invoked undefined behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see, the diff hid line 207 by default, but now i see that temp gets placed into leaf_vars. that makes much more sense :)

for (IterVar iv : threads) {
temp.push_back(iv);
}
Expand Down