| 1 |
// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,cplusplus.NewDelete -verify %s |
| 2 |
|
| 3 |
// expected-no-diagnostics: |
| 4 |
// From now the profile of the 'StackFrameContext' also contains the |
| 5 |
// 'NodeBuilderContext::blockCount()'. With this addition we can distinguish |
| 6 |
// between the 'StackArgumentsSpaceRegion' of the 'P' arguments being different |
| 7 |
// on every iteration. |
| 8 |
|
| 9 |
typedef __INTPTR_TYPE__ intptr_t; |
| 10 |
|
| 11 |
template <typename PointerTy> |
| 12 |
struct SmarterPointer { |
| 13 |
PointerTy getFromVoidPointer(void *P) const { |
| 14 |
return static_cast<PointerTy>(P); |
| 15 |
} |
| 16 |
|
| 17 |
PointerTy getPointer() const { |
| 18 |
return getFromVoidPointer(reinterpret_cast<void *>(Value)); |
| 19 |
} |
| 20 |
|
| 21 |
intptr_t Value = 13; |
| 22 |
}; |
| 23 |
|
| 24 |
struct Node { |
| 25 |
SmarterPointer<Node *> Pred; |
| 26 |
}; |
| 27 |
|
| 28 |
void test(Node *N) { |
| 29 |
while (N) { |
| 30 |
SmarterPointer<Node *> Next = N->Pred; |
| 31 |
delete N; |
| 32 |
|
| 33 |
N = Next.getPointer(); |
| 34 |
// no-warning: 'Use of memory after it is released' was here as the same |
| 35 |
// 'StackArgumentsSpaceRegion' purged out twice as 'P'. |
| 36 |
} |
| 37 |
} |