Skip to content

Commit

Permalink
c++11 size test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucylq committed May 3, 2024
1 parent c5598d1 commit b7006f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
16 changes: 9 additions & 7 deletions runtime/core/portable_type/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ class basic_string_view final {
}

constexpr const_reference at(size_type pos) const {
ET_CHECK_MSG(
pos >= size_,
"string_view::operator[] or string_view::at() out of range");
return at_(pos);
return __ET_UNLIKELY (!(pos >= size_))
? (ET_ASSERT_MESSAGE_EMIT(" (%s): " "string_view::operator[] or string_view::at() out of range", pos >= size_), torch::executor::runtime_abort())
: at_(pos);
}

constexpr const_reference front() const {
Expand Down Expand Up @@ -137,9 +136,12 @@ class basic_string_view final {

constexpr basic_string_view substr(size_type pos = 0, size_type count = npos)
const {
ET_CHECK_MSG(
pos > size_, "basic_string_view::substr parameter out of bounds.");
return substr_(pos, count);
return __ET_UNLIKELY (!(pos > size_))
? (ET_ASSERT_MESSAGE_EMIT(" (%s): " "basic_string_view::substr parameter out of bounds.", pos > size_), torch::executor::runtime_abort())
: substr_(pos, count);
// ET_CHECK_MSG(
// pos > size_, "basic_string_view::substr parameter out of bounds.");
// return substr_(pos, count);
}

constexpr int compare(basic_string_view rhs) const noexcept {
Expand Down
9 changes: 8 additions & 1 deletion runtime/platform/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@
* @param[in] _format Printf-style message format string.
* @param[in] ... Format string arguments.
*/
#define ET_CHECK_MSG(_cond, _format, ...) \
#define ET_CHECK_MSG(_cond, _format, ...) \
({ \
if __ET_UNLIKELY (!(_cond)) { \
ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \
torch::executor::runtime_abort(); \
} \
})
// #define ET_CHECK_MSG(_cond, _format, ...) \
// ({ \
// if __ET_UNLIKELY (!(_cond)) { \
// ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \
// torch::executor::runtime_abort(); \
// } \
// })

/**
* Abort the runtime if the condition is not true.
Expand Down
4 changes: 2 additions & 2 deletions test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compiler=$(cc --version)
if [[ $compiler == *"clang"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-extensions -Wc++14-extensions"
elif [[ $compiler == *"cc"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-compat"
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-compat -Wc++14-compat"
else
echo "Unknown compiler: $compiler"
exit 1
Expand All @@ -31,7 +31,7 @@ cmake_install_executorch_lib() {
rm -rf cmake-out

retry cmake -DBUCK2="$BUCK2" \
-DCMAKE_CXX_STANDARD=14 \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_INSTALL_PREFIX=cmake-out \
Expand Down

0 comments on commit b7006f3

Please sign in to comment.