llvm-project/clang/test/Analysis/NewDelete-path-notes.cpp
Baghirov Feyruz f0c90dfcd8
Rename 'free' in warning messages to 'release' (#150935)
Changed the warning message:

- **From**: 'Attempt to free released memory'
   **To**: 'Attempt to release already released memory'
- **From**: 'Attempt to free non-owned memory'
   **To**: 'Attempt to release non-owned memory'
- **From**: 'Use of memory after it is freed' 
   **To**: 'Use of memory after it is released'

All connected tests and their expectations have been changed
accordingly.

Inspired by [this
PR](https://github.com/llvm/llvm-project/pull/147542#discussion_r2195197922)
2025-07-28 18:02:56 +02:00

36 lines
1.2 KiB
C++

// RUN: %clang_analyze_cc1 \
// RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
// RUN: -analyzer-config add-pop-up-notes=false \
// RUN: -analyzer-output=text -verify %s
// RUN: %clang_analyze_cc1 \
// RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
// RUN: -analyzer-config add-pop-up-notes=false \
// RUN: -analyzer-output=plist %s -o %t.plist
// RUN: %normalize_plist <%t.plist | diff -ub \
// RUN: %S/Inputs/expected-plists/NewDelete-path-notes.cpp.plist -
void test() {
int *p = new int;
// expected-note@-1 {{Memory is allocated}}
if (p) // expected-note {{Taking true branch}}
delete p;
// expected-note@-1 {{Memory is released}}
delete p; // expected-warning {{Attempt to release already released memory}}
// expected-note@-1 {{Attempt to release already released memory}}
}
struct Odd {
void kill() {
delete this; // expected-note {{Memory is released}}
}
};
void test(Odd *odd) {
odd->kill(); // expected-note{{Calling 'Odd::kill'}}
// expected-note@-1 {{Returning; memory was released}}
delete odd; // expected-warning {{Attempt to release already released memory}}
// expected-note@-1 {{Attempt to release already released memory}}
}