Skip to content

Commit 1ed4d91

Browse files
bcahoonronlieb
authored andcommitted
Revert "[clang][Sema] Add -Wswitch-default warning option (llvm#73077)"
This reverts commit 2cf433b. Change-Id: I630da1ecf57cb003cc3062252b39e9e2b9ddf7d1
1 parent 180b86f commit 1ed4d91

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ Improvements to Clang's diagnostics
470470
of a base class is not called in the constructor of its derived class.
471471
- Clang no longer emits ``-Wmissing-variable-declarations`` for variables declared
472472
with the ``register`` storage class.
473-
- Clang's ``-Wswitch-default`` flag now diagnoses whenever a ``switch`` statement
474-
does not have a ``default`` label.
475473
- Clang's ``-Wtautological-negation-compare`` flag now diagnoses logical
476474
tautologies like ``x && !x`` and ``!x || x`` in expressions. This also
477475
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 SwitchDefault : DiagGroup<"switch-default">;
637+
def : 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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10098,8 +10098,6 @@ def warn_missing_case : Warning<"%plural{"
1009810098
"3:enumeration values %1, %2, and %3 not handled in switch|"
1009910099
":%0 enumeration values not handled in switch: %1, %2, %3...}0">,
1010010100
InGroup<Switch>;
10101-
def warn_switch_default : Warning<"'switch' missing 'default' label">,
10102-
InGroup<SwitchDefault>, DefaultIgnore;
1010310101

1010410102
def warn_unannotated_fallthrough : Warning<
1010510103
"unannotated fall-through between switch labels">,

clang/lib/Sema/SemaStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,10 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
13501350
assert(!HasConstantCond ||
13511351
(ConstantCondValue.getBitWidth() == CondWidth &&
13521352
ConstantCondValue.isSigned() == CondIsSigned));
1353+
#if NEEDS_PATCH_FOR_SWITCH
1354+
//[clang][Sema] Add -Wswitch-default warning option (#73077)
13531355
Diag(SwitchLoc, diag::warn_switch_default);
1356+
#endif
13541357
}
13551358
bool ShouldCheckConstantCond = HasConstantCond;
13561359

clang/test/Sema/switch-default.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wswitch-default %s
2+
3+
// XFAIL: *
4+
5+
int f1(int a) {
6+
switch (a) { // expected-warning {{'switch' missing 'default' label}}
7+
case 1: a++; break;
8+
case 2: a += 2; break;
9+
}
10+
return a;
11+
}
12+
13+
int f2(int a) {
14+
switch (a) { // no-warning
15+
default:
16+
;
17+
}
18+
return a;
19+
}
20+
21+
// Warn even completely covered Enum cases(GCC compatibility).
22+
enum E { A, B };
23+
enum E check_enum(enum E e) {
24+
switch (e) { // expected-warning {{'switch' missing 'default' label}}
25+
case A: break;
26+
case B: break;
27+
}
28+
return e;
29+
}
30+
31+
template<typename Index>
32+
int t1(Index i)
33+
{
34+
switch (i) { // expected-warning {{'switch' missing 'default' label}}
35+
case 0: return 0;
36+
case 1: return 1;
37+
}
38+
return 0;
39+
}
40+
41+
template<typename Index>
42+
int t2(Index i)
43+
{
44+
switch (i) { // no-warning
45+
case 0: return 0;
46+
case 1: return 1;
47+
default: return 2;
48+
}
49+
return 0;
50+
}
51+
52+
int main() {
53+
return t1(1); // expected-note {{in instantiation of function template specialization 't1<int>' requested here}}
54+
}
55+

revert_patches.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
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+
5+
Reverts: breaks ompt tests
6+
[Libomptarget] Remove __tgt_image_info and use the ELF directly (#75720)
7+
8+
64f0681e97c6 [Libomptarget] Rework image checking further (#76120)
9+
110
Reverts: breaks HIP tests in wPSDB and nPSDB
211
[AMDGPU] Add dynamic LDS size implicit kernel argument t

0 commit comments

Comments
 (0)