diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
commit | 461a67fa15370a9ec88f8f8a240bf7c123bb2029 (patch) | |
tree | 6942083d7d56bba40ec790a453ca58ad3baf6832 /test/Analysis/max-nodes-suppress-on-sink.c | |
parent | 75c3240472ba6ac2669ee72ca67eb72d4e2851fc (diff) | |
download | src-test2-vendor/clang/clang-trunk-r321017.tar.gz src-test2-vendor/clang/clang-trunk-r321017.zip |
Diffstat (limited to 'test/Analysis/max-nodes-suppress-on-sink.c')
-rw-r--r-- | test/Analysis/max-nodes-suppress-on-sink.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/Analysis/max-nodes-suppress-on-sink.c b/test/Analysis/max-nodes-suppress-on-sink.c index 8d955b91c1e3..da1e7bf02284 100644 --- a/test/Analysis/max-nodes-suppress-on-sink.c +++ b/test/Analysis/max-nodes-suppress-on-sink.c @@ -15,6 +15,8 @@ extern void exit(int) __attribute__ ((__noreturn__)); void clang_analyzer_warnIfReached(void); +int coin(); + void test_single_cfg_block_sink() { void *p = malloc(1); // no-warning (wherever the leak warning may occur here) @@ -29,3 +31,53 @@ void test_single_cfg_block_sink() { // the leak report. exit(0); } + +// A similar test with more complicated control flow before the no-return thing, +// so that the no-return thing wasn't in the same CFG block. +void test_more_complex_control_flow_before_sink() { + void *p = malloc(1); // no-warning + + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + clang_analyzer_warnIfReached(); // no-warning + + if (coin()) + exit(0); + else + exit(1); +} + +// A loop before the no-return function, to make sure that +// the dominated-by-sink analysis doesn't hang. +void test_loop_before_sink(int n) { + void *p = malloc(1); // no-warning + + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + clang_analyzer_warnIfReached(); // no-warning + + for (int i = 0; i < n; ++i) { + } + exit(1); +} + +// We're not sure if this is no-return. +void test_loop_with_sink(int n) { + void *p = malloc(1); // expected-warning@+2{{Potential leak of memory}} + + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + clang_analyzer_warnIfReached(); // no-warning + + for (int i = 0; i < n; ++i) + if (i == 0) + exit(1); +} + +// Handle unreachable blocks correctly. +void test_unreachable_successor_blocks() { + void *p = malloc(1); // no-warning + + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + clang_analyzer_warnIfReached(); // no-warning + + if (1) // no-crash + exit(1); +} |