From: Reid Kleckner Date: Fri, 17 Aug 2018 22:11:31 +0000 (+0000) Subject: Don't warn on returning the address of a label from a statement expression X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c33d197fa77b9434a7e76d9ee80005de58a0026;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 766f23b..1f28056 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6924,6 +6924,10 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity, } else if (isa(L)) { Diag(DiagLoc, diag::err_ret_local_block) << DiagRange; } else if (isa(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/clang/test/Sema/statements.c b/clang/test/Sema/statements.c index dbb4d56..ddaec8d 100644 --- a/clang/test/Sema/statements.c +++ b/clang/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)