warn about returning the address of a label.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85576 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-10-30 04:01:58 +00:00
Родитель d3379292f9
Коммит 9e6b37a9f1
3 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -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<

Просмотреть файл

@ -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

Просмотреть файл

@ -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}}
}