2013-04-05 19:25:10 +08:00
// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.MismatchedDeallocator -analyzer-output=text -verify %s
2013-06-04 07:00:19 +08:00
// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.MismatchedDeallocator -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false %s -o %t.plist
2013-04-05 19:25:10 +08:00
// RUN: FileCheck --input-file=%t.plist %s
2013-04-09 08:30:28 +08:00
void changePointee ( int * p ) ;
2013-04-05 19:25:10 +08:00
void test ( ) {
2015-05-15 04:57:48 +08:00
int * p = new int [ 1 ] ;
// expected-note@-1 {{Memory is allocated}}
2013-04-09 08:30:28 +08:00
changePointee ( p ) ;
2013-04-05 19:25:10 +08:00
delete p ; // expected-warning {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}}
// expected-note@-1 {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}}
}
2013-04-09 08:30:28 +08:00
// CHECK: <key>diagnostics</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>path</key>
// CHECK-NEXT: <array>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: <dict>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>kind</key><string>control</string>
// CHECK-NEXT: <key>edges</key>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>start</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2015-05-15 00:14:57 +08:00
// CHECK-NEXT: <key>line</key><integer>7</integer>
// CHECK-NEXT: <key>col</key><integer>3</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>5</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: <key>end</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>12</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>14</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>kind</key><string>event</string>
// CHECK-NEXT: <key>location</key>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>12</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <key>ranges</key>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: <array>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>12</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>7</integer>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>col</key><integer>21</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: </array>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>depth</key><integer>0</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>extended_message</key>
// CHECK-NEXT: <string>Memory is allocated</string>
// CHECK-NEXT: <key>message</key>
// CHECK-NEXT: <string>Memory is allocated</string>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: </dict>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>kind</key><string>control</string>
// CHECK-NEXT: <key>edges</key>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>start</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>7</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>12</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>7</integer>
// CHECK-NEXT: <key>col</key><integer>14</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: <key>end</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>3</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>8</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
2013-04-05 19:25:10 +08:00
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>kind</key><string>event</string>
// CHECK-NEXT: <key>location</key>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>3</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <key>ranges</key>
// CHECK-NEXT: <array>
// CHECK-NEXT: <array>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>10</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>10</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: </array>
// CHECK-NEXT: <key>depth</key><integer>0</integer>
// CHECK-NEXT: <key>extended_message</key>
// CHECK-NEXT: <string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string>
// CHECK-NEXT: <key>message</key>
// CHECK-NEXT: <string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: <key>description</key><string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string>
// CHECK-NEXT: <key>category</key><string>Memory Error</string>
// CHECK-NEXT: <key>type</key><string>Bad deallocator</string>
2015-02-10 06:52:26 +08:00
// CHECK-NEXT: <key>check_name</key><string>unix.MismatchedDeallocator</string>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>issue_context_kind</key><string>function</string>
// CHECK-NEXT: <key>issue_context</key><string>test</string>
// CHECK-NEXT: <key>issue_hash</key><string>4</string>
// CHECK-NEXT: <key>location</key>
// CHECK-NEXT: <dict>
2015-05-15 04:57:48 +08:00
// CHECK-NEXT: <key>line</key><integer>10</integer>
2013-04-09 08:30:28 +08:00
// CHECK-NEXT: <key>col</key><integer>3</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>