summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r--clang/test/Analysis/diagnostics/find_last_store.c6
-rw-r--r--clang/test/Analysis/track-control-dependency-conditions.cpp141
-rw-r--r--clang/test/Analysis/uninit-vals.c12
3 files changed, 126 insertions, 33 deletions
diff --git a/clang/test/Analysis/diagnostics/find_last_store.c b/clang/test/Analysis/diagnostics/find_last_store.c
index 9bf601ea30e..486e4ec64d1 100644
--- a/clang/test/Analysis/diagnostics/find_last_store.c
+++ b/clang/test/Analysis/diagnostics/find_last_store.c
@@ -2,13 +2,11 @@
typedef struct { float b; } c;
void *a();
void *d() {
- return a(); // expected-note{{Returning pointer}}
+ return a();
}
void no_find_last_store() {
- c *e = d(); // expected-note{{Calling 'd'}}
- // expected-note@-1{{Returning from 'd'}}
- // expected-note@-2{{'e' initialized here}}
+ c *e = d(); // expected-note{{'e' initialized here}}
(void)(e || e->b); // expected-note{{Assuming 'e' is null}}
// expected-note@-1{{Left side of '||' is false}}
diff --git a/clang/test/Analysis/track-control-dependency-conditions.cpp b/clang/test/Analysis/track-control-dependency-conditions.cpp
index d4e59a7ad67..93a5efb39db 100644
--- a/clang/test/Analysis/track-control-dependency-conditions.cpp
+++ b/clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -119,7 +119,7 @@ namespace variable_declaration_in_condition {
bool coin();
bool foo() {
- return coin(); // tracking-note{{Returning value}}
+ return coin();
}
int bar;
@@ -127,12 +127,10 @@ int bar;
void test() {
int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
- if (int flag = foo()) // tracking-note{{Calling 'foo'}}
- // tracking-note@-1{{Returning from 'foo'}}
- // tracking-note@-2{{'flag' initialized here}}
- // debug-note@-3{{Tracking condition 'flag'}}
- // expected-note@-4{{Assuming 'flag' is not equal to 0}}
- // expected-note@-5{{Taking true branch}}
+ if (int flag = foo()) // tracking-note{{'flag' initialized here}}
+ // debug-note@-1{{Tracking condition 'flag'}}
+ // expected-note@-2{{Assuming 'flag' is not equal to 0}}
+ // expected-note@-3{{Taking true branch}}
*x = 5; // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
@@ -143,39 +141,114 @@ namespace conversion_to_bool {
bool coin();
struct ConvertsToBool {
- operator bool() const { return coin(); } // tracking-note{{Returning value}}
+ operator bool() const { return coin(); }
};
void test() {
int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
if (ConvertsToBool())
- // tracking-note@-1 {{Calling 'ConvertsToBool::operator bool'}}
- // tracking-note@-2{{Returning from 'ConvertsToBool::operator bool'}}
- // debug-note@-3{{Tracking condition 'ConvertsToBool()'}}
- // expected-note@-4{{Assuming the condition is true}}
- // expected-note@-5{{Taking true branch}}
+ // debug-note@-1{{Tracking condition 'ConvertsToBool()'}}
+ // expected-note@-2{{Assuming the condition is true}}
+ // expected-note@-3{{Taking true branch}}
*x = 5; // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
}
} // end of namespace variable_declaration_in_condition
+namespace important_returning_pointer_loaded_from {
+bool coin();
+
+int *getIntPtr();
+
+void storeValue(int **i) {
+ *i = getIntPtr(); // tracking-note{{Value assigned to 'i'}}
+}
+
+int *conjurePointer() {
+ int *i;
+ storeValue(&i); // tracking-note{{Calling 'storeValue'}}
+ // tracking-note@-1{{Returning from 'storeValue'}}
+ return i; // tracking-note{{Returning pointer (loaded from 'i')}}
+}
+
+void f(int *ptr) {
+ if (ptr) // expected-note{{Assuming 'ptr' is null}}
+ // expected-note@-1{{Taking false branch}}
+ ;
+ if (!conjurePointer())
+ // tracking-note@-1{{Calling 'conjurePointer'}}
+ // tracking-note@-2{{Returning from 'conjurePointer'}}
+ // debug-note@-3{{Tracking condition '!conjurePointer()'}}
+ // expected-note@-4{{Assuming the condition is true}}
+ // expected-note@-5{{Taking true branch}}
+ *ptr = 5; // expected-warning{{Dereference of null pointer}}
+ // expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace important_returning_pointer_loaded_from
+
+namespace unimportant_returning_pointer_loaded_from {
+bool coin();
+
+int *getIntPtr();
+
+int *conjurePointer() {
+ int *i = getIntPtr(); // tracking-note{{'i' initialized here}}
+ return i; // tracking-note{{Returning pointer (loaded from 'i')}}
+}
+
+void f(int *ptr) {
+ if (ptr) // expected-note{{Assuming 'ptr' is null}}
+ // expected-note@-1{{Taking false branch}}
+ ;
+ if (!conjurePointer())
+ // tracking-note@-1{{Calling 'conjurePointer'}}
+ // tracking-note@-2{{Returning from 'conjurePointer'}}
+ // debug-note@-3{{Tracking condition '!conjurePointer()'}}
+ // expected-note@-4{{Assuming the condition is true}}
+ // expected-note@-5{{Taking true branch}}
+ *ptr = 5; // expected-warning{{Dereference of null pointer}}
+ // expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace unimportant_returning_pointer_loaded_from
+
+namespace unimportant_returning_pointer_loaded_from_through_cast {
+
+void *conjure();
+
+int *cast(void *P) {
+ return static_cast<int *>(P);
+}
+
+void f() {
+ int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+ if (cast(conjure()))
+ // tracking-note@-1{{Passing value via 1st parameter 'P'}}
+ // debug-note@-2{{Tracking condition 'cast(conjure())'}}
+ // expected-note@-3{{Assuming the condition is false}}
+ // expected-note@-4{{Taking false branch}}
+ return;
+ *x = 5; // expected-warning{{Dereference of null pointer}}
+ // expected-note@-1{{Dereference of null pointer}}
+}
+
+} // end of namespace unimportant_returning_pointer_loaded_from_through_cast
+
namespace unimportant_returning_value_note {
bool coin();
-bool flipCoin() { return coin(); } // tracking-note{{Returning value}}
+bool flipCoin() { return coin(); }
void i(int *ptr) {
if (ptr) // expected-note{{Assuming 'ptr' is null}}
// expected-note@-1{{Taking false branch}}
;
if (!flipCoin())
- // tracking-note@-1{{Calling 'flipCoin'}}
- // tracking-note@-2{{Returning from 'flipCoin'}}
- // debug-note@-3{{Tracking condition '!flipCoin()'}}
- // expected-note@-4{{Assuming the condition is true}}
- // expected-note@-5{{Taking true branch}}
+ // debug-note@-1{{Tracking condition '!flipCoin()'}}
+ // expected-note@-2{{Assuming the condition is true}}
+ // expected-note@-3{{Taking true branch}}
*ptr = 5; // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
}
@@ -207,6 +280,36 @@ void i(int *ptr) {
}
} // end of namespace important_returning_value_note
+namespace important_returning_value_note_in_linear_function {
+bool coin();
+
+struct super_complicated_template_hackery {
+ static constexpr bool value = false;
+};
+
+bool flipCoin() {
+ if (super_complicated_template_hackery::value)
+ // tracking-note@-1{{'value' is false}}
+ // tracking-note@-2{{Taking false branch}}
+ return true;
+ return coin(); // tracking-note{{Returning value}}
+}
+
+void i(int *ptr) {
+ if (ptr) // expected-note{{Assuming 'ptr' is null}}
+ // expected-note@-1{{Taking false branch}}
+ ;
+ if (!flipCoin())
+ // tracking-note@-1{{Calling 'flipCoin'}}
+ // tracking-note@-2{{Returning from 'flipCoin'}}
+ // debug-note@-3{{Tracking condition '!flipCoin()'}}
+ // expected-note@-4{{Assuming the condition is true}}
+ // expected-note@-5{{Taking true branch}}
+ *ptr = 5; // expected-warning{{Dereference of null pointer}}
+ // expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace important_returning_value_note_in_linear_function
+
namespace tracked_condition_is_only_initialized {
int getInt();
diff --git a/clang/test/Analysis/uninit-vals.c b/clang/test/Analysis/uninit-vals.c
index d24b4587473..c0c6034e803 100644
--- a/clang/test/Analysis/uninit-vals.c
+++ b/clang/test/Analysis/uninit-vals.c
@@ -149,8 +149,6 @@ int test_radar12278788_FP() {
RetVoidFuncType f = foo_radar12278788_fp;
return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}
//expected-note@-1 {{Undefined or garbage value returned to caller}}
- //expected-note@-2 {{Calling 'foo_radar12278788_fp'}}
- //expected-note@-3 {{Returning from 'foo_radar12278788_fp'}}
}
void rdar13665798() {
@@ -164,8 +162,6 @@ void rdar13665798() {
RetVoidFuncType f = foo_radar12278788_fp;
return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}
//expected-note@-1 {{Undefined or garbage value returned to caller}}
- //expected-note@-2 {{Calling 'foo_radar12278788_fp'}}
- //expected-note@-3 {{Returning from 'foo_radar12278788_fp'}}
}();
}
@@ -182,18 +178,14 @@ struct Point getHalfPoint() {
void use(struct Point p);
void testUseHalfPoint() {
- struct Point p = getHalfPoint(); // expected-note{{Calling 'getHalfPoint'}}
- // expected-note@-1{{Returning from 'getHalfPoint'}}
- // expected-note@-2{{'p' initialized here}}
+ struct Point p = getHalfPoint(); // expected-note{{'p' initialized here}}
use(p); // expected-warning{{uninitialized}}
// expected-note@-1{{uninitialized}}
}
void testUseHalfPoint2() {
struct Point p;
- p = getHalfPoint(); // expected-note{{Calling 'getHalfPoint'}}
- // expected-note@-1{{Returning from 'getHalfPoint'}}
- // expected-note@-2{{Value assigned to 'p'}}
+ p = getHalfPoint(); // expected-note{{Value assigned to 'p'}}
use(p); // expected-warning{{uninitialized}}
// expected-note@-1{{uninitialized}}
}
OpenPOWER on IntegriCloud