[PATCH] D50805: Don't warn on returning the address of a label from a statement expression

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 17 15:12:18 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC340101: Don't warn on returning the address of a label from a statement expression (authored by rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50805?vs=161148&id=161344#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50805

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/statements.c


Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6924,6 +6924,10 @@
       } 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)
Index: test/Sema/statements.c
===================================================================
--- test/Sema/statements.c
+++ test/Sema/statements.c
@@ -34,6 +34,15 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50805.161344.patch
Type: text/x-patch
Size: 1144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180817/5e47228b/attachment.bin>


More information about the cfe-commits mailing list