Skip to content

Commit 4c33d19

Browse files
committedAug 17, 2018
Don't warn on returning the address of a label from a statement expression
Summary: There isn't anything inherently wrong with returning a label from a statement expression. In practice, the Linux kernel uses this pattern to materialize PCs. Fixes PR38569 Reviewers: niravd, rsmith, nickdesaulniers Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50805 llvm-svn: 340101
1 parent 26f6176 commit 4c33d19

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎clang/lib/Sema/SemaInit.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -6924,6 +6924,10 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
69246924
} else if (isa<BlockExpr>(L)) {
69256925
Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
69266926
} else if (isa<AddrLabelExpr>(L)) {
6927+
// Don't warn when returning a label from a statement expression.
6928+
// Leaving the scope doesn't end its lifetime.
6929+
if (LK == LK_StmtExprResult)
6930+
return false;
69276931
Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
69286932
} else {
69296933
Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)

‎clang/test/Sema/statements.c

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ void *test10() {
3434
return &&bar; // expected-warning {{returning address of label, which is local}}
3535
}
3636

37+
// PR38569: Don't warn when returning a label from a statement expression.
38+
void test10_logpc(void*);
39+
void test10a() {
40+
test10_logpc(({
41+
my_pc:
42+
&&my_pc;
43+
}));
44+
}
45+
3746
// PR6034
3847
void test11(int bit) {
3948
switch (bit)

0 commit comments

Comments
 (0)
Please sign in to comment.