brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1004 B · bd2f046 Raw
38 lines · cpp
1// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,cplusplus.NewDelete -verify %s2 3// expected-no-diagnostics:4// From now the profile of the 'StackFrameContext' also contains the5// 'NodeBuilderContext::blockCount()'. With this addition we can distinguish6// between the 'StackArgumentsSpaceRegion' of the 'P' arguments being different7// 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 released' was here as the same35    //             'StackArgumentsSpaceRegion' purged out twice as 'P'.36  }37}38