diff options
| author | Ted Kremenek <kremenek@apple.com> | 2012-09-13 00:21:35 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2012-09-13 00:21:35 +0000 |
| commit | edf22edca014b5e347cb138cad5d21b6203fa38d (patch) | |
| tree | 33efdeacd69ffcf287ab8fc00ecd8ef8f8154ac5 /clang/test/SemaObjC/uninit-variables.m | |
| parent | 8b3f93869772ef9e1fc667c3dff78fa5cd8ee492 (diff) | |
| download | bcm5719-llvm-edf22edca014b5e347cb138cad5d21b6203fa38d.tar.gz bcm5719-llvm-edf22edca014b5e347cb138cad5d21b6203fa38d.zip | |
Teach -Wuninitialized to recognize common "noreturn" idioms in
Objective-C related to NSException.
Fixes <rdar://problem/12287498>
I debated whether or not this logic should be sunk into the CFG
itself. It's not clear if we should, as different analyses may
wish to have different policies. We can re-evaluate this in the
future.
llvm-svn: 163760
Diffstat (limited to 'clang/test/SemaObjC/uninit-variables.m')
| -rw-r--r-- | clang/test/SemaObjC/uninit-variables.m | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/uninit-variables.m b/clang/test/SemaObjC/uninit-variables.m index cad0f54b2dd..a3312264f0c 100644 --- a/clang/test/SemaObjC/uninit-variables.m +++ b/clang/test/SemaObjC/uninit-variables.m @@ -1,5 +1,16 @@ // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fblocks %s -verify +#include <stdarg.h> + +@interface NSObject {} @end +@class NSString; + +@interface NSException ++ (void)raise:(NSString *)name format:(NSString *)format, ...; ++ (void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)argList; +- (void)raise; +@end + // Duplicated from uninit-variables.c. // Test just to ensure the analysis is working. int test1() { @@ -25,3 +36,21 @@ void test3() { } } +int test_abort_on_exceptions(int y, NSException *e, NSString *s, int *z, ...) { + int x; // expected-note {{initialize the variable 'x' to silence this warning}} + if (y == 1) { + va_list alist; + va_start(alist, z); + [NSException raise:@"Blah" format:@"Blah %@" arguments:alist]; + return x; + } + else if (y == 2) { + [NSException raise:@"Blah" format:s]; + return x; + } + else if (y == 3) { + [e raise]; + return x; + } + return x; // expected-warning {{variable 'x' is uninitialized when used here}} +} |

