summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/inline.c
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-01-12 19:25:46 +0000
committerTed Kremenek <kremenek@apple.com>2012-01-12 19:25:46 +0000
commit3d3aea9374d745d76f9b448e42dec0d56d5f54ab (patch)
treee2d9cad52677e51da5e8bfa5357e6eb2bc243a6b /clang/test/Analysis/inline.c
parent9eae723c1800d6dec010c0fed7a929596cec21b5 (diff)
downloadbcm5719-llvm-3d3aea9374d745d76f9b448e42dec0d56d5f54ab.tar.gz
bcm5719-llvm-3d3aea9374d745d76f9b448e42dec0d56d5f54ab.zip
[analyzer] fix inlining's handling of mapping actual to formal arguments and limit the call stack depth. The analyzer can now accurately simulate factorial for limited depths.
llvm-svn: 148036
Diffstat (limited to 'clang/test/Analysis/inline.c')
-rw-r--r--clang/test/Analysis/inline.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/test/Analysis/inline.c b/clang/test/Analysis/inline.c
index e3c7e838934..de807fb3aad 100644
--- a/clang/test/Analysis/inline.c
+++ b/clang/test/Analysis/inline.c
@@ -28,3 +28,33 @@ void test2_f3() {
test2_f1(test2_f2()); // expected-warning{{too many arguments in call to 'test2_f1'}}
}
+// Test that inlining works with recursive functions.
+
+unsigned factorial(unsigned x) {
+ if (x <= 1)
+ return 1;
+ return x * factorial(x - 1);
+}
+
+void test_factorial() {
+ if (factorial(3) == 6) {
+ int *p = 0;
+ *p = 0xDEADBEEF; // expected-warning {{null}}
+ }
+ else {
+ int *p = 0;
+ *p = 0xDEADBEEF; // no-warning
+ }
+}
+
+void test_factorial_2() {
+ unsigned x = factorial(3);
+ if (x == factorial(3)) {
+ int *p = 0;
+ *p = 0xDEADBEEF; // expected-warning {{null}}
+ }
+ else {
+ int *p = 0;
+ *p = 0xDEADBEEF; // no-warning
+ }
+}
OpenPOWER on IntegriCloud