forked from OSchip/llvm-project
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
This commit is contained in:
parent
26f6176f38
commit
4c33d197fa
|
@ -6924,6 +6924,10 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
|
||||||
} else if (isa<BlockExpr>(L)) {
|
} else if (isa<BlockExpr>(L)) {
|
||||||
Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
|
Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
|
||||||
} else if (isa<AddrLabelExpr>(L)) {
|
} else if (isa<AddrLabelExpr>(L)) {
|
||||||
|
// Don't warn when returning a label from a statement expression.
|
||||||
|
// Leaving the scope doesn't end its lifetime.
|
||||||
|
if (LK == LK_StmtExprResult)
|
||||||
|
return false;
|
||||||
Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
|
Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
|
||||||
} else {
|
} else {
|
||||||
Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
|
Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
|
||||||
|
|
|
@ -34,6 +34,15 @@ bar:
|
||||||
return &&bar; // expected-warning {{returning address of label, which is local}}
|
return &&bar; // expected-warning {{returning address of label, which is local}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR38569: Don't warn when returning a label from a statement expression.
|
||||||
|
void test10_logpc(void*);
|
||||||
|
void test10a() {
|
||||||
|
test10_logpc(({
|
||||||
|
my_pc:
|
||||||
|
&&my_pc;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
// PR6034
|
// PR6034
|
||||||
void test11(int bit) {
|
void test11(int bit) {
|
||||||
switch (bit)
|
switch (bit)
|
||||||
|
|
Loading…
Reference in New Issue