Artem Dergachev | b0914e7 | 2019-10-19 00:08:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,cplusplus.NewDelete -verify %s |
Csaba Dabis | 7740c6d | 2019-08-01 20:41:13 +0000 | [diff] [blame] | 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 freed' was here as the same |
| 35 | // 'StackArgumentsSpaceRegion' purged out twice as 'P'. |
| 36 | } |
| 37 | } |