From 7979ccf35aa987ea49c77a96a2af3b871a88b0f3 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 12 Sep 2012 05:53:43 +0000 Subject: Teach -Wuninitialized to recognize __attribute__((analyzer_noreturn)) for halting the propagation of uninitialized value tracking along a path. Unlike __attribute__((noreturn)), this attribute (which is used by clients of the static analyzer) can be used to annotate functions that essentially never return, but in rare cares may be allowed to return for (special) debugging purposes. This attribute has been shown in reducing false positives in the static analyzer by pruning false postives, and is equally applicable here. Handling this attribute in the CFG itself is another option, but this is not something all clients (e.g., possibly -Wunreachable-code) would want to see. Addresses . llvm-svn: 163681 --- clang/test/Sema/uninit-variables.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'clang/test/Sema/uninit-variables.c') diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c index 634ae0dc428..9e3dd9d2875 100644 --- a/clang/test/Sema/uninit-variables.c +++ b/clang/test/Sema/uninit-variables.c @@ -508,3 +508,26 @@ int self_init_in_cond(int *p) { int n = ((p && (0 || 1)) && (n = *p)) ? n : -1; // ok return n; } + +void test_analyzer_noreturn_aux() __attribute__((analyzer_noreturn)); + +void test_analyzer_noreturn(int y) { + int x; // expected-note {{initialize the variable 'x' to silence this warning}} + if (y) { + test_analyzer_noreturn_aux(); + ++x; // no-warning + } + else { + ++x; // expected-warning {{variable 'x' is uninitialized when used here}} + } +} +void test_analyzer_noreturn_2(int y) { + int x; + if (y) { + test_analyzer_noreturn_aux(); + } + else { + x = 1; + } + ++x; // no-warning +} -- cgit v1.2.3