diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
| commit | c0c7bca4e5b8d12699dc93a0da49e9e4bb79671b (patch) | |
| tree | 508d4388db78f87d35bf26a0400b4b03bc4c1f13 /test/Analysis | |
| parent | 4a37f65f1c1373c9956d118a012943de2f61edb0 (diff) | |
Notes
Diffstat (limited to 'test/Analysis')
| -rw-r--r-- | test/Analysis/dead-stores.c | 33 | ||||
| -rw-r--r-- | test/Analysis/misc-ps-region-store.m | 22 | ||||
| -rw-r--r-- | test/Analysis/uninit-vals-ps-region.m (renamed from test/Analysis/uninit-vals-ps-region.c) | 15 |
3 files changed, 57 insertions, 13 deletions
diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index 9a266c937939..209ca6531cc2 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -1,18 +1,18 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s void f1() { - int k, y; + int k, y; // expected-warning{{unused variable 'k'}} expected-warning{{unused variable 'y'}} int abc=1; - long idx=abc+3*5; // expected-warning {{never read}} + long idx=abc+3*5; // expected-warning {{never read}} expected-warning{{unused variable 'idx'}} } void f2(void *b) { char *c = (char*)b; // no-warning - char *d = b+1; // expected-warning {{never read}} + char *d = b+1; // expected-warning {{never read}} expected-warning{{unused variable 'd'}} printf("%s", c); // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} } @@ -40,7 +40,7 @@ void f4(int k) { void f5() { int x = 4; // no-warning - int *p = &x; // expected-warning{{never read}} + int *p = &x; // expected-warning{{never read}} expected-warning{{unused variable 'p'}} } @@ -105,13 +105,20 @@ int f11b() { } int f12a(int y) { - int x = y; // expected-warning{{never read}} + int x = y; // expected-warning{{unused variable 'x'}} return 1; } int f12b(int y) { int x __attribute__((unused)) = y; // no-warning return 1; } +int f12c(int y) { + // Allow initialiation of scalar variables by parameters as a form of + // defensive programming. + int x = y; // no-warning + x = 1; + return x; +} // Filed with PR 2630. This code should produce no warnings. int f13(void) @@ -138,7 +145,7 @@ int f14(int count) { // Test case for <rdar://problem/6248086> void f15(unsigned x, unsigned y) { int count = x * y; // no-warning - int z[count]; + int z[count]; // expected-warning{{unused variable 'z'}} } int f16(int x) { @@ -367,7 +374,7 @@ void f23(int argc, char **argv) { } void f23_pos(int argc, char **argv) { - int shouldLog = (argc > 1); // expected-warning{{Value stored to 'shouldLog' during its initialization is never read}} + int shouldLog = (argc > 1); // expected-warning{{Value stored to 'shouldLog' during its initialization is never read}} expected-warning{{unused variable 'shouldLog'}} ^{ f23_aux("I did too use it!\n"); }(); @@ -377,7 +384,7 @@ void f24_A(int y) { // FIXME: One day this should be reported as dead since 'z = x + y' is dead. int x = (y > 2); // no-warning ^ { - int z = x + y; // expected-warning{{Value stored to 'z' during its initialization is never read}} + int z = x + y; // expected-warning{{Value stored to 'z' during its initialization is never read}} expected-warning{{unused variable 'z'}} }(); } diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index 21a54c34d78f..898a33efe124 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -888,3 +888,25 @@ char *rdar_7242010(int count, char **y) { return y[0]; // no-warning } +//===----------------------------------------------------------------------===// +// <rdar://problem/7770737> +//===----------------------------------------------------------------------===// + +struct rdar_7770737_s { intptr_t p; }; +void rdar_7770737_aux(struct rdar_7770737_s *p); +int rdar_7770737(void) +{ + int x; + + // Previously 'f' was not properly invalidated, causing the use of + // an uninitailized value below. + struct rdar_7770737_s f = { .p = (intptr_t)&x }; + rdar_7770737_aux(&f); + return x; // no-warning +} +int rdar_7770737_pos(void) +{ + int x; + struct rdar_7770737_s f = { .p = (intptr_t)&x }; + return x; // expected-warning{{Undefined or garbage value returned to caller}} +} diff --git a/test/Analysis/uninit-vals-ps-region.c b/test/Analysis/uninit-vals-ps-region.m index 44f506efadb2..7e2fff9db530 100644 --- a/test/Analysis/uninit-vals-ps-region.c +++ b/test/Analysis/uninit-vals-ps-region.m @@ -45,3 +45,18 @@ void test_uninit_neg() { test_unit_aux2(v2.x + v1.y); // no-warning } +extern void test_uninit_struct_arg_aux(struct TestUninit arg); +void test_uninit_struct_arg() { + struct TestUninit x; + test_uninit_struct_arg_aux(x); // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}} +} + +@interface Foo +- (void) passVal:(struct TestUninit)arg; +@end +void testFoo(Foo *o) { + struct TestUninit x; + [o passVal:x]; // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}} +} + + |
