summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/stack-addr-ps.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2013-07-26 11:50:42 +0000
committerPavel Labath <labath@google.com>2013-07-26 11:50:42 +0000
commitcf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6 (patch)
treef00c5294fa6452b542d3d8caf1f33ade145f5183 /clang/test/Analysis/stack-addr-ps.cpp
parent240d480c5f6ae6cbfe40bfb40d83164008a99b09 (diff)
downloadbcm5719-llvm-cf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6.tar.gz
bcm5719-llvm-cf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6.zip
[analyzer] Fix FP warnings when binding a temporary to a local static variable
Summary: When binding a temporary object to a static local variable, the analyzer would complain about a dangling reference even though the temporary's lifetime should be extended past the end of the function. This commit tries to detect these cases and construct them in a global memory region instead of a local one. Reviewers: jordan_rose CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1133 llvm-svn: 187196
Diffstat (limited to 'clang/test/Analysis/stack-addr-ps.cpp')
-rw-r--r--clang/test/Analysis/stack-addr-ps.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/test/Analysis/stack-addr-ps.cpp b/clang/test/Analysis/stack-addr-ps.cpp
index 65d757154c8..a39f9c7dc72 100644
--- a/clang/test/Analysis/stack-addr-ps.cpp
+++ b/clang/test/Analysis/stack-addr-ps.cpp
@@ -20,6 +20,10 @@ const int& g3() {
return s3; // expected-warning{{Address of stack memory associated with local variable 's1' returned}} expected-warning {{reference to stack memory associated with local variable 's1' returned}}
}
+void g4() {
+ static const int &x = 3; // no warning
+}
+
int get_value();
const int &get_reference1() { return get_value(); } // expected-warning{{Address of stack memory associated with temporary object of type 'int' returned}} expected-warning {{returning reference to local temporary}}
OpenPOWER on IntegriCloud