diff options
author | Kristof Umann <dkszelethus@gmail.com> | 2018-09-14 08:58:21 +0000 |
---|---|---|
committer | Kristof Umann <dkszelethus@gmail.com> | 2018-09-14 08:58:21 +0000 |
commit | f0dd1016da7bb4a84f099182a0fae9895c280512 (patch) | |
tree | 3ee7627fde17aca4f6372927c93c1f0ae8dcf298 /clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp | |
parent | 89fc26466c3d6a0c16f75768e6fcd4b1f603b739 (diff) | |
download | bcm5719-llvm-f0dd1016da7bb4a84f099182a0fae9895c280512.tar.gz bcm5719-llvm-f0dd1016da7bb4a84f099182a0fae9895c280512.zip |
[analyzer][UninitializedObjectChecker] Fixed dereferencing
iThis patch aims to fix derefencing, which has been debated for months now.
Instead of working with SVals, the function now relies on TypedValueRegion.
Differential Revision: https://reviews.llvm.org/D51057
llvm-svn: 342213
Diffstat (limited to 'clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp')
-rw-r--r-- | clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp index f214a86adfc..4ee113c9e8f 100644 --- a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp +++ b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp @@ -46,6 +46,50 @@ void fNullPtrTest() { } //===----------------------------------------------------------------------===// +// Alloca tests. +//===----------------------------------------------------------------------===// + +struct UntypedAllocaTest { + void *allocaPtr; + int dontGetFilteredByNonPedanticMode = 0; + + UntypedAllocaTest() : allocaPtr(__builtin_alloca(sizeof(int))) { + // All good! + } +}; + +void fUntypedAllocaTest() { + UntypedAllocaTest(); +} + +struct TypedAllocaTest1 { + int *allocaPtr; // expected-note{{uninitialized pointee 'this->allocaPtr'}} + int dontGetFilteredByNonPedanticMode = 0; + + TypedAllocaTest1() // expected-warning{{1 uninitialized field}} + : allocaPtr(static_cast<int *>(__builtin_alloca(sizeof(int)))) {} +}; + +void fTypedAllocaTest1() { + TypedAllocaTest1(); +} + +struct TypedAllocaTest2 { + int *allocaPtr; + int dontGetFilteredByNonPedanticMode = 0; + + TypedAllocaTest2() + : allocaPtr(static_cast<int *>(__builtin_alloca(sizeof(int)))) { + *allocaPtr = 55555; + // All good! + } +}; + +void fTypedAllocaTest2() { + TypedAllocaTest2(); +} + +//===----------------------------------------------------------------------===// // Heap pointer tests. //===----------------------------------------------------------------------===// @@ -203,18 +247,14 @@ void fCyclicPointerTest1() { CyclicPointerTest1(); } -// TODO: Currently, the checker ends up in an infinite loop for the following -// test case. -/* struct CyclicPointerTest2 { - int **pptr; + int **pptr; // no-crash CyclicPointerTest2() : pptr(reinterpret_cast<int **>(&pptr)) {} }; void fCyclicPointerTest2() { CyclicPointerTest2(); } -*/ //===----------------------------------------------------------------------===// // Void pointer tests. @@ -471,6 +511,39 @@ void fMultiPointerTest3() { } //===----------------------------------------------------------------------===// +// Incomplete pointee tests. +//===----------------------------------------------------------------------===// + +class IncompleteType; + +struct IncompletePointeeTypeTest { + IncompleteType *pImpl; //no-crash + int dontGetFilteredByNonPedanticMode = 0; + + IncompletePointeeTypeTest(IncompleteType *A) : pImpl(A) {} +}; + +void fIncompletePointeeTypeTest(void *ptr) { + IncompletePointeeTypeTest(reinterpret_cast<IncompleteType *>(ptr)); +} + +//===----------------------------------------------------------------------===// +// Function pointer tests. +//===----------------------------------------------------------------------===// + +struct FunctionPointerWithDifferentDynTypeTest { + using Func1 = void *(*)(); + using Func2 = int *(*)(); + + Func1 f; // no-crash + FunctionPointerWithDifferentDynTypeTest(Func2 f) : f((Func1)f) {} +}; + +// Note that there isn't a function calling the constructor of +// FunctionPointerWithDifferentDynTypeTest, because a crash could only be +// reproduced without it. + +//===----------------------------------------------------------------------===// // Member pointer tests. //===----------------------------------------------------------------------===// @@ -645,6 +718,15 @@ void fCyclicList() { CyclicList(&n1, int()); } +struct RingListTest { + RingListTest *next; // no-crash + RingListTest() : next(this) {} +}; + +void fRingListTest() { + RingListTest(); +} + //===----------------------------------------------------------------------===// // Tests for classes containing references. //===----------------------------------------------------------------------===// |