| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s |
| 2 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -fsized-deallocation |
| 3 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -DINCLUDE_INCLUDES |
| 4 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -DINCLUDE_INCLUDES -fsized-deallocation |
| 5 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS |
| 6 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS -fsized-deallocation |
| 7 |
|
| 8 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 |
| 9 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 -fsized-deallocation |
| 10 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 -DINCLUDE_INCLUDES |
| 11 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 -DINCLUDE_INCLUDES -fsized-deallocation |
| 12 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS |
| 13 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++14 -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS -fsized-deallocation |
| 14 |
|
| 15 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 |
| 16 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 -fsized-deallocation |
| 17 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 -DINCLUDE_INCLUDES |
| 18 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 -DINCLUDE_INCLUDES -fsized-deallocation |
| 19 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS |
| 20 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus -verify -analyzer-output=text %s -std=c++17 -DINCLUDE_INCLUDES -DTEST_INLINABLE_ALLOCATORS -fsized-deallocation |
| 21 |
|
| 22 |
// Test all three: undeclared operator delete, operator delete forward-declared |
| 23 |
// in the system header, operator delete defined in system header. |
| 24 |
#ifdef INCLUDE_INCLUDES |
| 25 |
// TEST_INLINABLE_ALLOCATORS is used within this include. |
| 26 |
#include "Inputs/system-header-simulator-cxx.h" |
| 27 |
#endif |
| 28 |
|
| 29 |
void leak() { |
| 30 |
int *x = new int; // expected-note{{Memory is allocated}} |
| 31 |
} // expected-warning{{Potential leak of memory pointed to by 'x'}} |
| 32 |
// expected-note@-1{{Potential leak of memory pointed to by 'x'}} |
| 33 |
|
| 34 |
// This function was incorrectly diagnosed as leak under -fsized-deallocation |
| 35 |
// because the sized operator delete was mistaken for a custom delete. |
| 36 |
void no_leak() { |
| 37 |
int *x = new int; // no-note |
| 38 |
delete x; |
| 39 |
} // no-warning |