| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core.NullDereference,core.uninitialized.UndefReturn -std=c++11 %s -verify -o /dev/null |
| 2 |
|
| 3 |
void test_static_assert() { |
| 4 |
static_assert(sizeof(void *) == sizeof(void*), "test_static_assert"); |
| 5 |
} |
| 6 |
|
| 7 |
void test_analyzer_working() { |
| 8 |
int *p = 0; |
| 9 |
*p = 0xDEADBEEF; // expected-warning {{null}} |
| 10 |
} |
| 11 |
|
| 12 |
// Test that pointer-to-member functions don't cause the analyzer |
| 13 |
// to crash. |
| 14 |
struct RDar10243398 { |
| 15 |
void bar(int x); |
| 16 |
}; |
| 17 |
|
| 18 |
typedef void (RDar10243398::*RDar10243398MemberFn)(int x); |
| 19 |
|
| 20 |
void test_rdar10243398(RDar10243398 *p) { |
| 21 |
RDar10243398MemberFn q = &RDar10243398::bar; |
| 22 |
((*p).*(q))(1); |
| 23 |
} |
| 24 |
|
| 25 |
// Tests for CXXTemporaryObjectExpr. |
| 26 |
struct X { |
| 27 |
X( int *ip, int ); |
| 28 |
}; |
| 29 |
|
| 30 |
// Test to see if CXXTemporaryObjectExpr is being handled. |
| 31 |
int tempobj1() |
| 32 |
{ |
| 33 |
int j; |
| 34 |
int i; |
| 35 |
X a = X( &j, 1 ); |
| 36 |
|
| 37 |
return i; // expected-warning {{Undefined or garbage value returned to caller}} |
| 38 |
} |
| 39 |
|
| 40 |
// Test to see if CXXTemporaryObjectExpr invalidates arguments. |
| 41 |
int tempobj2() |
| 42 |
{ |
| 43 |
int j; |
| 44 |
X a = X( &j, 1 ); |
| 45 |
|
| 46 |
return j; // no-warning |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
// Test for correct handling of C++ ForRange statement. |
| 51 |
void test1() { |
| 52 |
int array[2] = { 1, 2 }; |
| 53 |
int j = 0; |
| 54 |
for ( int i : array ) |
| 55 |
j += i; |
| 56 |
int *p = 0; |
| 57 |
*p = 0xDEADBEEF; // expected-warning {{null}} |
| 58 |
} |
| 59 |
|
| 60 |
void test2() { |
| 61 |
int array[2] = { 1, 2 }; |
| 62 |
int j = 0; |
| 63 |
for (int i : array) |
| 64 |
j += i; |
| 65 |
if (j == 3) |
| 66 |
return; |
| 67 |
int *p = 0; |
| 68 |
*p = 0xDEADBEEF; // no-warning |
| 69 |
} |
| 70 |
|
| 71 |
// Do not crash on the following when constructing the |
| 72 |
// callgraph. |
| 73 |
struct RDar11178609 { |
| 74 |
~RDar11178609() = delete; |
| 75 |
}; |
| 76 |
|
| 77 |
// Tests that dynamic_cast handles references to C++ classes. Previously |
| 78 |
// this crashed. |
| 79 |
class rdar11817693_BaseBase {}; |
| 80 |
class rdar11817693_BaseInterface {}; |
| 81 |
class rdar11817693_Base : public rdar11817693_BaseBase, public rdar11817693_BaseInterface {}; |
| 82 |
class rdar11817693 : public rdar11817693_Base { |
| 83 |
virtual void operator=(const rdar11817693_BaseBase& src); |
| 84 |
void operator=(const rdar11817693& src); |
| 85 |
}; |
| 86 |
void rdar11817693::operator=(const rdar11817693& src) { |
| 87 |
operator=(dynamic_cast<const rdar11817693_BaseBase&>(src)); |
| 88 |
} |
| 89 |
|