Skip to content

Commit 02ca6ac

Browse files
NSProgrammerfacebook-github-bot
authored andcommitted
Fix missing enum values in switch statements (executorch) (pytorch#15515)
Summary: `-Wswitch-enum` was introduced in 2024 and is beneficial because it will err when switch statement is missing a case for an enum, even with `default:` present. This helps alert developers when they add an enum value of all the switch statements that need updating. These diffs are to help progress the codebase so that we can enable `-Wswitch-enum` by default in `fbobjc` Reviewed By: shoumikhin Differential Revision: D85956878
1 parent 4a75896 commit 02ca6ac

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchLog.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void et_pal_emit_log_message(et_timestamp_t timestamp,
151151
case kFatal:
152152
logType = OS_LOG_TYPE_FAULT;
153153
break;
154+
case kUnknown:
154155
default:
155156
logType = OS_LOG_TYPE_DEFAULT;
156157
break;

extension/tensor/tensor_ptr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
#include <memory>
1414
#include <vector>
1515

16+
#include <c10/macros/Macros.h>
1617
#include <executorch/runtime/core/error.h>
1718
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1819
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
1920

21+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wswitch-enum")
22+
2023
namespace executorch {
2124
namespace extension {
2225

@@ -445,3 +448,5 @@ runtime::Error resize_tensor_ptr(
445448

446449
} // namespace extension
447450
} // namespace executorch
451+
452+
C10_DIAGNOSTIC_POP()

runtime/core/exec_aten/util/scalar_type_util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
#include <limits>
2828
#include <type_traits>
2929

30+
#include <c10/macros/Macros.h>
3031
#include <executorch/runtime/platform/assert.h>
3132

33+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wswitch-enum")
34+
3235
#ifdef USE_ATEN_LIB
3336
// Note that a lot of the macros/functions defined in this ScalarTypeUtil.h file
3437
// are also defined in c10/core/ScalarType.h, which is included via
@@ -1421,3 +1424,5 @@ using ::executorch::runtime::internal::U1;
14211424
} // namespace internal
14221425
} // namespace executor
14231426
} // namespace torch
1427+
1428+
C10_DIAGNOSTIC_POP()

0 commit comments

Comments
 (0)