aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td6
-rw-r--r--lib/Sema/SemaChecking.cpp7
-rw-r--r--test/Sema/statements.c6
3 files changed, 16 insertions, 3 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 1ce4d91a17..00723a3af9 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2140,6 +2140,10 @@ def warn_ret_stack_addr : Warning<
"address of stack memory associated with local variable %0 returned">;
def warn_ret_stack_ref : Warning<
"reference to stack memory associated with local variable %0 returned">;
+def warn_ret_addr_label : Warning<
+ "returning address of label, which is local">;
+def err_ret_local_block : Error<
+ "returning block that lives on the local stack">;
// For non-floating point, expressions of the form x == x or x != x
@@ -2163,8 +2167,6 @@ def err_return_in_block_expression : Error<
def err_block_returns_array : Error<
"block declared as returning an array">;
-def err_ret_local_block : Error<
- "returning block that lives on the local stack">;
// CFString checking
def err_cfstring_literal_not_string_constant : Error<
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index b7ccedec70..38b6ebeefa 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -1272,10 +1272,15 @@ Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
// Skip over implicit cast expressions when checking for block expressions.
RetValExp = RetValExp->IgnoreParenCasts();
- if (BlockExpr *C = dyn_cast_or_null<BlockExpr>(RetValExp))
+ if (BlockExpr *C = dyn_cast<BlockExpr>(RetValExp))
if (C->hasBlockDeclRefExprs())
Diag(C->getLocStart(), diag::err_ret_local_block)
<< C->getSourceRange();
+
+ if (AddrLabelExpr *ALE = dyn_cast<AddrLabelExpr>(RetValExp))
+ Diag(ALE->getLocStart(), diag::warn_ret_addr_label)
+ << ALE->getSourceRange();
+
} else if (lhsType->isReferenceType()) {
// Perform checking for stack values returned by reference.
// Check for a reference to the stack
diff --git a/test/Sema/statements.c b/test/Sema/statements.c
index 9a71a40370..8eac052a25 100644
--- a/test/Sema/statements.c
+++ b/test/Sema/statements.c
@@ -27,3 +27,9 @@ int test8[({10;})]; // expected-error {{statement expression not allowed at file
void test9(const void *P) {
__builtin_prefetch(P);
}
+
+
+void *test10() {
+bar:
+ return &&bar; // expected-warning {{returning address of label, which is local}}
+}