diff options
author | Reid Kleckner <rnk@google.com> | 2018-08-17 22:18:56 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-08-17 22:18:56 +0000 |
commit | deea4eee5de7c93740402afdb85a595635c78606 (patch) | |
tree | e0f9b981febe5d7e3b9a87e38872acdaf06d93f1 | |
parent | 8901ecd01a3004e983024c29b94c423ed08342d8 (diff) |
Merging r340101:
------------------------------------------------------------------------
r340101 | rnk | 2018-08-17 15:11:31 -0700 (Fri, 17 Aug 2018) | 14 lines
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
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_70@340103 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaInit.cpp | 4 | ||||
-rw-r--r-- | test/Sema/statements.c | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 01ef86c656..5070996d50 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -6942,6 +6942,10 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity, } else if (isa<BlockExpr>(L)) { Diag(DiagLoc, diag::err_ret_local_block) << DiagRange; } 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; } else { Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref) diff --git a/test/Sema/statements.c b/test/Sema/statements.c index dbb4d56ee1..ddaec8d433 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -34,6 +34,15 @@ bar: 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 void test11(int bit) { switch (bit) |