Skip to content

Commit 2cf433b

Browse files
dongjianqiang2ronlieb
authored andcommitted
[clang][Sema] Add -Wswitch-default warning option (llvm#73077)
Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. Change-Id: Iba221a303560b88fd7e408a517cfba2d728b0931
1 parent 9f8bc08 commit 2cf433b

File tree

6 files changed

+5
-63
lines changed

6 files changed

+5
-63
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ Improvements to Clang's diagnostics
436436
of a base class is not called in the constructor of its derived class.
437437
- Clang no longer emits ``-Wmissing-variable-declarations`` for variables declared
438438
with the ``register`` storage class.
439+
- Clang's ``-Wswitch-default`` flag now diagnoses whenever a ``switch`` statement
440+
does not have a ``default`` label.
439441
- Clang's ``-Wtautological-negation-compare`` flag now diagnoses logical
440442
tautologies like ``x && !x`` and ``!x || x`` in expressions. This also
441443
makes ``-Winfinite-recursion`` diagnose more cases.

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor,
634634
def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
635635
def : DiagGroup<"sign-promo">;
636636
def SignCompare : DiagGroup<"sign-compare">;
637-
def : DiagGroup<"switch-default">;
637+
def SwitchDefault : DiagGroup<"switch-default">;
638638
def : DiagGroup<"synth">;
639639
def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">;
640640
def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10085,6 +10085,8 @@ def warn_missing_case : Warning<"%plural{"
1008510085
"3:enumeration values %1, %2, and %3 not handled in switch|"
1008610086
":%0 enumeration values not handled in switch: %1, %2, %3...}0">,
1008710087
InGroup<Switch>;
10088+
def warn_switch_default : Warning<"'switch' missing 'default' label">,
10089+
InGroup<SwitchDefault>, DefaultIgnore;
1008810090

1008910091
def warn_unannotated_fallthrough : Warning<
1009010092
"unannotated fall-through between switch labels">,

clang/lib/Sema/SemaStmt.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
13441344
assert(!HasConstantCond ||
13451345
(ConstantCondValue.getBitWidth() == CondWidth &&
13461346
ConstantCondValue.isSigned() == CondIsSigned));
1347-
#if NEEDS_PATCH_FOR_SWITCH
1348-
//[clang][Sema] Add -Wswitch-default warning option (#73077)
13491347
Diag(SwitchLoc, diag::warn_switch_default);
1350-
#endif
13511348
}
13521349
bool ShouldCheckConstantCond = HasConstantCond;
13531350

clang/test/Sema/switch-default.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

revert_patches.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
revert: breaks MIOpen composableKernel build
2-
[clang][Sema] Add -Wswitch-default warning option (#73077)
3-
https://ontrack-internal.amd.com/browse/SWDEV-436625
4-
51
Reverts: breaks ompt tests
62
[Libomptarget] Remove __tgt_image_info and use the ELF directly (#75720)
73

0 commit comments

Comments
 (0)