[cfe-commits] r89940 - in /cfe/trunk: lib/Analysis/ReturnStackAddressChecker.cpp test/Analysis/stack-addr-ps.c
Ted Kremenek
kremenek at apple.com
Wed Nov 25 23:14:50 PST 2009
Author: kremenek
Date: Thu Nov 26 01:14:50 2009
New Revision: 89940
URL: http://llvm.org/viewvc/llvm-project?rev=89940&view=rev
Log:
Improve diagnostics in ReturnStackAddressChecker for returning a stack-allocated block. Implements the rest of <rdar://problem/7387385>.
Modified:
cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp
cfe/trunk/test/Analysis/stack-addr-ps.c
Modified: cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp?rev=89940&r1=89939&r2=89940&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp (original)
+++ cfe/trunk/lib/Analysis/ReturnStackAddressChecker.cpp Thu Nov 26 01:14:50 2009
@@ -83,6 +83,14 @@
<< C.getSourceManager().getInstantiationLineNumber(L)
<< " returned to caller";
}
+ else if (const BlockDataRegion *BR = dyn_cast<BlockDataRegion>(R)) {
+ const BlockDecl *BD = BR->getCodeRegion()->getDecl();
+ SourceLocation L = BD->getLocStart();
+ range = BD->getSourceRange();
+ os << "Address of stack-allocated block declared on line "
+ << C.getSourceManager().getInstantiationLineNumber(L)
+ << " returned to caller";
+ }
else {
os << "Address of stack memory associated with local variable '"
<< R->getString() << "' returned.";
Modified: cfe/trunk/test/Analysis/stack-addr-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/stack-addr-ps.c?rev=89940&r1=89939&r2=89940&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/stack-addr-ps.c (original)
+++ cfe/trunk/test/Analysis/stack-addr-ps.c Thu Nov 26 01:14:50 2009
@@ -1,5 +1,5 @@
-// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s
-// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s
+// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -fblocks -verify %s
+// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -fblocks -verify %s
int* f1() {
int x = 0;
@@ -55,3 +55,16 @@
return byVal.y[0]; // no-warning
}
}
+
+typedef int (^ComparatorBlock)(int a, int b);
+ComparatorBlock test_return_block(void) {
+ ComparatorBlock b = ^int(int a, int b){ return a > b; };
+ return b; // expected-warning{{Address of stack-allocated block declared on line 61 returned to caller}}
+}
+
+ComparatorBlock test_return_block_neg_aux(void);
+ComparatorBlock test_return_block_neg(void) {
+ ComparatorBlock b = test_return_block_neg_aux();
+ return b; // no-warning
+}
+
More information about the cfe-commits
mailing list