NewDelete-path-notes.cpp 1.2 KB

123456789101112131415161718192021222324252627282930
  1. // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -verify %s
  2. // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -analyzer-config c++-allocator-inlining=true -verify %s
  3. // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=plist %s -o %t.plist
  4. // RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  5. void test() {
  6. int *p = new int;
  7. // expected-note@-1 {{Memory is allocated}}
  8. if (p)
  9. // expected-note@-1 {{Taking true branch}}
  10. delete p;
  11. // expected-note@-1 {{Memory is released}}
  12. delete p; // expected-warning {{Attempt to free released memory}}
  13. // expected-note@-1 {{Attempt to free released memory}}
  14. }
  15. struct Odd {
  16. void kill() {
  17. delete this; // expected-note {{Memory is released}}
  18. }
  19. };
  20. void test(Odd *odd) {
  21. odd->kill(); // expected-note{{Calling 'Odd::kill'}}
  22. // expected-note@-1 {{Returning; memory was released}}
  23. delete odd; // expected-warning {{Attempt to free released memory}}
  24. // expected-note@-1 {{Attempt to free released memory}}
  25. }