// RUN: %clang_cc1 -analyze -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -verify %s
// RUN: %clang_cc1 -analyze -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false %s -o %t.plist
// RUN: FileCheck --input-file=%t.plist %s
void test() {
int *p = new int;
// expected-note@-1 {{Memory is allocated}}
if (p)
// expected-note@-1 {{Taking true branch}}
delete p;
// expected-note@-1 {{Memory is released}}
delete p; // expected-warning {{Attempt to free released memory}}
// expected-note@-1 {{Attempt to free 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 free released memory}}
// expected-note@-1 {{Attempt to free released memory}}
}
// CHECK: diagnostics
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: path
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col14
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col18
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Memory is allocated
// CHECK-NEXT: message
// CHECK-NEXT: Memory is allocated
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line6
// CHECK-NEXT: col14
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line8
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line8
// CHECK-NEXT: col4
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line8
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line8
// CHECK-NEXT: col4
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col10
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Memory is released
// CHECK-NEXT: message
// CHECK-NEXT: Memory is released
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line10
// CHECK-NEXT: col10
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col8
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col10
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Attempt to free released memory
// CHECK-NEXT: message
// CHECK-NEXT: Attempt to free released memory
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: descriptionAttempt to free released memory
// CHECK-NEXT: categoryMemory Error
// CHECK-NEXT: typeDouble free
// CHECK-NEXT: check_namecplusplus.NewDelete
// CHECK-NEXT:
// CHECK-NEXT: issue_hash_content_of_line_in_contextbd8e324d09c70b9e2be6f824a4942e5a
// CHECK-NEXT: issue_context_kindfunction
// CHECK-NEXT: issue_contexttest
// CHECK-NEXT: issue_hash_function_offset8
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line13
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: path
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Calling 'Odd::kill'
// CHECK-NEXT: message
// CHECK-NEXT: Calling 'Odd::kill'
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line18
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: depth1
// CHECK-NEXT: extended_message
// CHECK-NEXT: Entered call from 'test'
// CHECK-NEXT: message
// CHECK-NEXT: Entered call from 'test'
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line18
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line18
// CHECK-NEXT: col5
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line19
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line19
// CHECK-NEXT: col8
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line19
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line19
// CHECK-NEXT: col3
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line19
// CHECK-NEXT: col13
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth1
// CHECK-NEXT: extended_message
// CHECK-NEXT: Memory is released
// CHECK-NEXT: message
// CHECK-NEXT: Memory is released
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col12
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Returning; memory was released
// CHECK-NEXT: message
// CHECK-NEXT: Returning; memory was released
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindcontrol
// CHECK-NEXT: edges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: start
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line24
// CHECK-NEXT: col4
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: end
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col7
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: kindevent
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT: ranges
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col11
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: depth0
// CHECK-NEXT: extended_message
// CHECK-NEXT: Attempt to free released memory
// CHECK-NEXT: message
// CHECK-NEXT: Attempt to free released memory
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: descriptionAttempt to free released memory
// CHECK-NEXT: categoryMemory Error
// CHECK-NEXT: typeDouble free
// CHECK-NEXT: check_namecplusplus.NewDelete
// CHECK-NEXT:
// CHECK-NEXT: issue_hash_content_of_line_in_context8bf1a5b9fdae9d86780aa6c4cdce2605
// CHECK-NEXT: issue_context_kindfunction
// CHECK-NEXT: issue_contexttest
// CHECK-NEXT: issue_hash_function_offset3
// CHECK-NEXT: location
// CHECK-NEXT:
// CHECK-NEXT: line26
// CHECK-NEXT: col2
// CHECK-NEXT: file0
// CHECK-NEXT:
// CHECK-NEXT:
// CHECK-NEXT: