-
Notifications
You must be signed in to change notification settings - Fork 4k
Handle int overflow in rnn #28003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle int overflow in rnn #28003
Changes from 5 commits
cc4057c
88cff57
4a90ef8
372f0bf
e093efd
674c2ad
795675a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "core/common/safeint.h" | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <limits> | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace onnxruntime::test { | ||
|
|
||
| static_assert(is_supported_integer_v<int>); | ||
| static_assert(is_supported_integer_v<uint8_t>); | ||
| static_assert(!is_supported_integer_v<bool>); | ||
|
|
||
| TEST(SafeIntTest, SafeMulMultipliesOperands) { | ||
| EXPECT_EQ(SafeMul<size_t>(size_t{2}, 3U), size_t{6}); | ||
| EXPECT_EQ(SafeMul<int>(-2, 3, 4), -24); | ||
| } | ||
|
|
||
| TEST(SafeIntTest, SafeMulHandlesSameVariableOperands) { | ||
| const int value = 7; | ||
| EXPECT_EQ(SafeMul<int>(value, value), 49); | ||
| } | ||
|
|
||
| #ifndef ORT_NO_EXCEPTIONS | ||
| TEST(SafeIntTest, SafeMulThrowsOnInitialCastOverflow) { | ||
| EXPECT_THROW((SafeMul<uint32_t>(-1, 2)), OnnxRuntimeException); | ||
|
Check warning on line 30 in onnxruntime/test/common/safeint_test.cc
|
||
| } | ||
|
|
||
| TEST(SafeIntTest, SafeMulThrowsOnMultiplyOverflow) { | ||
| EXPECT_THROW((SafeMul<int>(std::numeric_limits<int>::max(), 2)), OnnxRuntimeException); | ||
|
Check warning on line 34 in onnxruntime/test/common/safeint_test.cc
|
||
| } | ||
| #endif | ||
|
|
||
| } // namespace onnxruntime::test | ||
Uh oh!
There was an error while loading. Please reload this page.