blob: 51f86defe3154e16d60111f1f2dca7aa10ea3852 [file] [log] [blame]
Artem Dergachevb0914e72019-10-19 00:08:17 +00001// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,cplusplus.NewDelete -verify %s
Csaba Dabis7740c6d2019-08-01 20:41:13 +00002
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
9typedef __INTPTR_TYPE__ intptr_t;
10
11template <typename PointerTy>
12struct 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
24struct Node {
25 SmarterPointer<Node *> Pred;
26};
27
28void 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}