Skip to content

Commit d470bfe

Browse files
camccamc
andauthored
[clang] Mark labels referenced when used in named break or continue (llvm#166033)
Fixes llvm#166013 Marks labels that appear in a c2y named break or continue statement as referenced to fix false-positive unused diagnostics. --------- Co-authored-by: camc <pushy-crop-cartel@duck.com>
1 parent c63cb50 commit d470bfe

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ Improvements to Clang's diagnostics
395395
that were previously incorrectly accepted in case of other irrelevant
396396
conditions are now consistently diagnosed, identical to C++ mode.
397397

398+
- Fix false-positive unused label diagnostic when a label is used in a named break
399+
or continue (#GH166013)
398400
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
399401
attributes are used with a negative size (#GH165463).
400402

clang/lib/Sema/SemaStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,9 @@ static Scope *FindLabeledBreakContinueScope(Sema &S, Scope *CurScope,
32813281
SourceLocation LabelLoc,
32823282
bool IsContinue) {
32833283
assert(Target && "not a named break/continue?");
3284+
3285+
Target->markUsed(S.Context);
3286+
32843287
Scope *Found = nullptr;
32853288
for (Scope *Scope = CurScope; Scope; Scope = Scope->getParent()) {
32863289
if (Scope->isFunctionScope())

clang/test/Sema/labeled-break-continue.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -std=c2y -verify -fsyntax-only -fblocks %s
2-
// RUN: %clang_cc1 -std=c23 -verify -fsyntax-only -fblocks -fnamed-loops %s
3-
// RUN: %clang_cc1 -x c++ -verify -fsyntax-only -fblocks -fnamed-loops %s
1+
// RUN: %clang_cc1 -std=c2y -verify -Wunused -fsyntax-only -fblocks %s
2+
// RUN: %clang_cc1 -std=c23 -verify -Wunused -fsyntax-only -fblocks -fnamed-loops %s
3+
// RUN: %clang_cc1 -x c++ -verify -Wunused -fsyntax-only -fblocks -fnamed-loops %s
44

55
void f1() {
66
l1: while (true) {
@@ -159,3 +159,15 @@ void f7() {
159159
continue d; // expected-error {{'continue' label does not name an enclosing loop}}
160160
}
161161
}
162+
163+
void f8() {
164+
l1: // no-warning
165+
while (true) {
166+
break l1;
167+
}
168+
169+
l2: // no-warning
170+
while (true) {
171+
continue l2;
172+
}
173+
}

0 commit comments

Comments
 (0)