diff options
Diffstat (limited to 'test/Analysis')
-rw-r--r-- | test/Analysis/analyzer-config.c | 4 | ||||
-rw-r--r-- | test/Analysis/analyzer-config.cpp | 4 | ||||
-rw-r--r-- | test/Analysis/builtin-assume.c | 8 | ||||
-rw-r--r-- | test/Analysis/builtin-functions.cpp | 14 | ||||
-rw-r--r-- | test/Analysis/copypaste/autogenerated_automoc.cpp | 19 | ||||
-rw-r--r-- | test/Analysis/copypaste/dbus_autogenerated.cpp | 19 | ||||
-rw-r--r-- | test/Analysis/copypaste/moc_autogenerated.cpp | 19 | ||||
-rw-r--r-- | test/Analysis/copypaste/not-autogenerated.cpp | 14 | ||||
-rw-r--r-- | test/Analysis/copypaste/ui_autogenerated.cpp | 19 | ||||
-rw-r--r-- | test/Analysis/null-deref-ps-region.c | 61 |
10 files changed, 167 insertions, 14 deletions
diff --git a/test/Analysis/analyzer-config.c b/test/Analysis/analyzer-config.c index c0153a50532a7..70521c63fbade 100644 --- a/test/Analysis/analyzer-config.c +++ b/test/Analysis/analyzer-config.c @@ -19,8 +19,8 @@ void foo() { // CHECK-NEXT: ipa = dynamic-bifurcate // CHECK-NEXT: ipa-always-inline-size = 3 // CHECK-NEXT: leak-diagnostics-reference-allocation = false -// CHECK-NEXT: max-inlinable-size = 50 -// CHECK-NEXT: max-nodes = 150000 +// CHECK-NEXT: max-inlinable-size = 100 +// CHECK-NEXT: max-nodes = 225000 // CHECK-NEXT: max-times-inline-large = 32 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14 // CHECK-NEXT: mode = deep diff --git a/test/Analysis/analyzer-config.cpp b/test/Analysis/analyzer-config.cpp index f84be17811608..60c03c1e497b2 100644 --- a/test/Analysis/analyzer-config.cpp +++ b/test/Analysis/analyzer-config.cpp @@ -30,8 +30,8 @@ public: // CHECK-NEXT: ipa = dynamic-bifurcate // CHECK-NEXT: ipa-always-inline-size = 3 // CHECK-NEXT: leak-diagnostics-reference-allocation = false -// CHECK-NEXT: max-inlinable-size = 50 -// CHECK-NEXT: max-nodes = 150000 +// CHECK-NEXT: max-inlinable-size = 100 +// CHECK-NEXT: max-nodes = 225000 // CHECK-NEXT: max-times-inline-large = 32 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14 // CHECK-NEXT: mode = deep diff --git a/test/Analysis/builtin-assume.c b/test/Analysis/builtin-assume.c deleted file mode 100644 index 00d651d9e3bec..0000000000000 --- a/test/Analysis/builtin-assume.c +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s - -void clang_analyzer_eval(int); - -void f(int i) { - __builtin_assume(i < 10); - clang_analyzer_eval(i < 15); // expected-warning {{TRUE}} -} diff --git a/test/Analysis/builtin-functions.cpp b/test/Analysis/builtin-functions.cpp index 4e9859754d628..2c1950251145c 100644 --- a/test/Analysis/builtin-functions.cpp +++ b/test/Analysis/builtin-functions.cpp @@ -1,6 +1,7 @@ // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify void clang_analyzer_eval(bool); +void clang_analyzer_warnIfReached(); void testAddressof(int x) { clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}} @@ -50,3 +51,16 @@ void test_assume_aligned_4(char *p) { q = (char*) __builtin_assume_aligned(p + 1, 16); clang_analyzer_eval(p == q); // expected-warning{{FALSE}} } + +void f(int i) { + __builtin_assume(i < 10); + clang_analyzer_eval(i < 15); // expected-warning {{TRUE}} +} + +void g(int i) { + if (i > 5) { + __builtin_assume(i < 5); + clang_analyzer_warnIfReached(); // Assumtion contradicts constraints. + // We give up the analysis on this path. + } +} diff --git a/test/Analysis/copypaste/autogenerated_automoc.cpp b/test/Analysis/copypaste/autogenerated_automoc.cpp new file mode 100644 index 0000000000000..55963c4545c9a --- /dev/null +++ b/test/Analysis/copypaste/autogenerated_automoc.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:IgnoredFilesPattern="moc_|.*_automoc.cpp" -verify %s + +// Because files that have `_automoc.' in their names are most likely autogenerated, +// we suppress copy-paste warnings here. + +// expected-no-diagnostics + +void f1() { + int *p1 = new int[1]; + int *p2 = new int[1]; + if (p1) { + delete [] p1; + p1 = nullptr; + } + if (p2) { + delete [] p1; // no-warning + p2 = nullptr; + } +} diff --git a/test/Analysis/copypaste/dbus_autogenerated.cpp b/test/Analysis/copypaste/dbus_autogenerated.cpp new file mode 100644 index 0000000000000..1824375658130 --- /dev/null +++ b/test/Analysis/copypaste/dbus_autogenerated.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:IgnoredFilesPattern="moc_|dbus_|.*_automoc" -verify %s + +// Because files that have `dbus_' in their names are most likely autogenerated, +// we suppress copy-paste warnings here. + +// expected-no-diagnostics + +void f1() { + int *p1 = new int[1]; + int *p2 = new int[1]; + if (p1) { + delete [] p1; + p1 = nullptr; + } + if (p2) { + delete [] p1; // no-warning + p2 = nullptr; + } +} diff --git a/test/Analysis/copypaste/moc_autogenerated.cpp b/test/Analysis/copypaste/moc_autogenerated.cpp new file mode 100644 index 0000000000000..626fe2a3dd070 --- /dev/null +++ b/test/Analysis/copypaste/moc_autogenerated.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:IgnoredFilesPattern="moc_|.*_automoc" -verify %s + +// Because files that have `moc_' in their names are most likely autogenerated, +// we suppress copy-paste warnings here. + +// expected-no-diagnostics + +void f1() { + int *p1 = new int[1]; + int *p2 = new int[1]; + if (p1) { + delete [] p1; + p1 = nullptr; + } + if (p2) { + delete [] p1; // no-warning + p2 = nullptr; + } +} diff --git a/test/Analysis/copypaste/not-autogenerated.cpp b/test/Analysis/copypaste/not-autogenerated.cpp new file mode 100644 index 0000000000000..765e7aaf2aab6 --- /dev/null +++ b/test/Analysis/copypaste/not-autogenerated.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:IgnoredFilesPattern="moc_|ui_|dbus_|.*_automoc" -verify %s + +void f1() { + int *p1 = new int[1]; + int *p2 = new int[1]; + if (p1) { + delete [] p1; // expected-note{{Similar code using 'p1' here}} + p1 = nullptr; + } + if (p2) { + delete [] p1; // expected-warning{{Potential copy-paste error; did you really mean to use 'p1' here?}} + p2 = nullptr; + } +} diff --git a/test/Analysis/copypaste/ui_autogenerated.cpp b/test/Analysis/copypaste/ui_autogenerated.cpp new file mode 100644 index 0000000000000..a08c33fe9e2a0 --- /dev/null +++ b/test/Analysis/copypaste/ui_autogenerated.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:IgnoredFilesPattern="moc_|ui_|.*_automoc" -verify %s + +// Because files that have `ui_' in their names are most likely autogenerated, +// we suppress copy-paste warnings here. + +// expected-no-diagnostics + +void f1() { + int *p1 = new int[1]; + int *p2 = new int[1]; + if (p1) { + delete [] p1; + p1 = nullptr; + } + if (p2) { + delete [] p1; // no-warning + p2 = nullptr; + } +} diff --git a/test/Analysis/null-deref-ps-region.c b/test/Analysis/null-deref-ps-region.c index 6ef99ae473ca8..c46ca6c52ae34 100644 --- a/test/Analysis/null-deref-ps-region.c +++ b/test/Analysis/null-deref-ps-region.c @@ -1,6 +1,11 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-store=region -verify %s -// expected-no-diagnostics +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,unix,alpha.unix -std=gnu99 -analyzer-store=region -verify %s +#include "Inputs/system-header-simulator.h" + +typedef __typeof(sizeof(int)) size_t; +void *memset(void *__s, int __c, size_t __n); +void *malloc(size_t __size); +void free(void *__ptr); // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may // also be live roots. @@ -13,3 +18,55 @@ void f14(int *a) { i = *p; // no-warning } } + +void foo() { + int *x = malloc(sizeof(int)); + memset(x, 0, sizeof(int)); + int n = 1 / *x; // FIXME: no-warning + free(x); +} + +void bar() { + int *x = malloc(sizeof(int)); + memset(x, 0, 1); + int n = 1 / *x; // no-warning + free(x); +} + +void testConcreteNull() { + int *x = 0; + memset(x, 0, 1); // expected-warning {{Null pointer argument in call to memory set function}} +} + +void testStackArray() { + char buf[13]; + memset(buf, 0, 1); // no-warning +} + +void testHeapSymbol() { + char *buf = (char *)malloc(13); + memset(buf, 0, 1); // no-warning + free(buf); +} + +void testStackArrayOutOfBound() { + char buf[1]; + memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}} +} + +void testHeapSymbolOutOfBound() { + char *buf = (char *)malloc(1); + memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}} + free(buf); +} + +void testStackArraySameSize() { + char buf[1]; + memset(buf, 0, sizeof(buf)); // no-warning +} + +void testHeapSymbolSameSize() { + char *buf = (char *)malloc(1); + memset(buf, 0, 1); // no-warning + free(buf); +} |