r340101 - Don't warn on returning the address of a label from a statement expression
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 17 15:11:32 PDT 2018
Author: rnk
Date: Fri Aug 17 15:11:31 2018
New Revision: 340101
URL: http://llvm.org/viewvc/llvm-project?rev=340101&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/statements.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=340101&r1=340100&r2=340101&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 17 15:11:31 2018
@@ -6924,6 +6924,10 @@ void Sema::checkInitializerLifetime(cons
} 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)
Modified: cfe/trunk/test/Sema/statements.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/statements.c?rev=340101&r1=340100&r2=340101&view=diff
==============================================================================
--- cfe/trunk/test/Sema/statements.c (original)
+++ cfe/trunk/test/Sema/statements.c Fri Aug 17 15:11:31 2018
@@ -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)
More information about the cfe-commits
mailing list