Skip to content

Commit 6ab1086

Browse files
dulinrileyfacebook-github-bot
authored andcommitted
Improve ET_ASSERT_UNREACHABLE_MSG to use formatting (pytorch#6802)
Summary: The macro `ET_ASSERT_UNREACHABLE_MSG` didn't allow for format strings unlike the other `ET_CHECK` macros. Add this capability and fix any users of it. Reviewed By: dbort Differential Revision: D65693396
1 parent ee14ad0 commit 6ab1086

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

extension/aten_util/aten_bridge.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ torch::executor::ScalarType torch_to_executorch_scalar_type(
9090
case c10::ScalarType::QUInt8:
9191
return torch::executor::ScalarType::QUInt8;
9292
default:
93-
ET_ASSERT_UNREACHABLE();
93+
ET_ASSERT_UNREACHABLE_MSG(
94+
"Unrecognized dtype: %hhd",
95+
static_cast<int8_t>(c10::typeMetaToScalarType(type)));
9496
}
9597
}
9698

@@ -122,7 +124,8 @@ c10::ScalarType executorch_to_torch_scalar_type(
122124
case torch::executor::ScalarType::QUInt8:
123125
return c10::ScalarType::QUInt8;
124126
default:
125-
ET_ASSERT_UNREACHABLE();
127+
ET_ASSERT_UNREACHABLE_MSG(
128+
"Unrecognized dtype: %hhd", static_cast<int8_t>(type));
126129
}
127130
}
128131

extension/pybindings/pybindings.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ struct PyModule final {
745745
} else if (py::isinstance<py::int_>(python_input)) {
746746
cpp_inputs.push_back(EValue(py::cast<int64_t>(python_input)));
747747
} else {
748-
// Unsupported pytype
749-
ET_ASSERT_UNREACHABLE_MSG(type_str.c_str());
748+
ET_ASSERT_UNREACHABLE_MSG("Unsupported pytype: %s", type_str.c_str());
750749
}
751750
}
752751

runtime/platform/assert.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@
112112
*
113113
* @param[in] _message Message on how to avoid this assertion error.
114114
*/
115-
#define ET_ASSERT_UNREACHABLE_MSG(_message) \
116-
({ \
117-
ET_CHECK_MSG( \
118-
false, "Execution should not reach this point. %s", _message); \
119-
ET_UNREACHABLE(); \
120-
})
115+
#define ET_ASSERT_UNREACHABLE_MSG(_format, ...) \
116+
do { \
117+
ET_CHECK_MSG( \
118+
false, \
119+
"Execution should not reach this point. " _format, \
120+
##__VA_ARGS__); \
121+
ET_UNREACHABLE(); \
122+
} while (0)

0 commit comments

Comments
 (0)