Skip to content

Commit e229d7c

Browse files
dulinrileyfacebook-github-bot
authored andcommitted
Improve ET_ASSERT_UNREACHABLE_MSG to use formatting
Differential Revision: D65693396
1 parent 07c4d0e commit e229d7c

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
@@ -114,9 +114,11 @@
114114
*
115115
* @param[in] _message Message on how to avoid this assertion error.
116116
*/
117-
#define ET_ASSERT_UNREACHABLE_MSG(_message) \
118-
({ \
119-
ET_CHECK_MSG( \
120-
false, "Execution should not reach this point. %s", _message); \
121-
ET_UNREACHABLE(); \
122-
})
117+
#define ET_ASSERT_UNREACHABLE_MSG(_format, ...) \
118+
do { \
119+
ET_CHECK_MSG( \
120+
false, \
121+
"Execution should not reach this point. " _format, \
122+
##__VA_ARGS__); \
123+
ET_UNREACHABLE(); \
124+
} while (0)

0 commit comments

Comments
 (0)