diff --git a/clang/test/Analysis/array-struct-region.c b/clang/test/Analysis/array-struct-region.c new file mode 100644 index 000000000000..2966d13004e0 --- /dev/null +++ b/clang/test/Analysis/array-struct-region.c @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s + +int string_literal_init() { + char a[] = "abc"; + char b[2] = "abc"; // expected-warning{{too long}} + char c[5] = "abc"; + + if (a[1] != 'b') + return 0; // expected-warning{{never executed}} + if (b[1] != 'b') + return 0; // expected-warning{{never executed}} + if (c[1] != 'b') + return 0; // expected-warning{{never executed}} + + if (a[3] != 0) + return 0; // expected-warning{{never executed}} + if (c[3] != 0) + return 0; // expected-warning{{never executed}} + + if (c[4] != 0) + return 0; // expected-warning{{never executed}} + + return 42; +} diff --git a/clang/test/Analysis/array-struct.c b/clang/test/Analysis/array-struct.c index ef9907bb579d..3e46a0a62235 100644 --- a/clang/test/Analysis/array-struct.c +++ b/clang/test/Analysis/array-struct.c @@ -178,26 +178,3 @@ void f18() { if (*q) { // no-warning } } - -int f19() { - char a[] = "abc"; - char b[2] = "abc"; // expected-warning{{too long}} - char c[5] = "abc"; - - if (a[1] != 'b') - return 5; // expected-warning{{never executed}} - if (b[1] != 'b') - return 5; // expected-warning{{never executed}} - if (c[1] != 'b') - return 5; // expected-warning{{never executed}} - - if (a[3] != 0) - return 5; // expected-warning{{never executed}} - if (c[3] != 0) - return 5; // expected-warning{{never executed}} - - if (c[4] != 0) - return 5; // expected-warning{{never executed}} - - return 0; -}