Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.MismatchedDeallocator -analyzer-output=text -verify %s
      2 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.MismatchedDeallocator -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false %s -o %t.plist
      3 // RUN: FileCheck --input-file=%t.plist %s
      4 
      5 void changePointee(int *p);
      6 void test() {
      7   int *p = new int[1];
      8   // expected-note@-1 {{Memory is allocated}}
      9   changePointee(p);
     10   delete p; // expected-warning {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}}
     11   // expected-note@-1 {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}}
     12 }
     13 
     14 // CHECK: <key>diagnostics</key>
     15 // CHECK-NEXT: <array>
     16 // CHECK-NEXT:  <dict>
     17 // CHECK-NEXT:   <key>path</key>
     18 // CHECK-NEXT:   <array>
     19 // CHECK-NEXT:    <dict>
     20 // CHECK-NEXT:     <key>kind</key><string>control</string>
     21 // CHECK-NEXT:     <key>edges</key>
     22 // CHECK-NEXT:      <array>
     23 // CHECK-NEXT:       <dict>
     24 // CHECK-NEXT:        <key>start</key>
     25 // CHECK-NEXT:         <array>
     26 // CHECK-NEXT:          <dict>
     27 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     28 // CHECK-NEXT:           <key>col</key><integer>3</integer>
     29 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     30 // CHECK-NEXT:          </dict>
     31 // CHECK-NEXT:          <dict>
     32 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     33 // CHECK-NEXT:           <key>col</key><integer>5</integer>
     34 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     35 // CHECK-NEXT:          </dict>
     36 // CHECK-NEXT:         </array>
     37 // CHECK-NEXT:        <key>end</key>
     38 // CHECK-NEXT:         <array>
     39 // CHECK-NEXT:          <dict>
     40 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     41 // CHECK-NEXT:           <key>col</key><integer>12</integer>
     42 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     43 // CHECK-NEXT:          </dict>
     44 // CHECK-NEXT:          <dict>
     45 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     46 // CHECK-NEXT:           <key>col</key><integer>14</integer>
     47 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     48 // CHECK-NEXT:          </dict>
     49 // CHECK-NEXT:         </array>
     50 // CHECK-NEXT:       </dict>
     51 // CHECK-NEXT:      </array>
     52 // CHECK-NEXT:    </dict>
     53 // CHECK-NEXT:    <dict>
     54 // CHECK-NEXT:     <key>kind</key><string>event</string>
     55 // CHECK-NEXT:     <key>location</key>
     56 // CHECK-NEXT:     <dict>
     57 // CHECK-NEXT:      <key>line</key><integer>7</integer>
     58 // CHECK-NEXT:      <key>col</key><integer>12</integer>
     59 // CHECK-NEXT:      <key>file</key><integer>0</integer>
     60 // CHECK-NEXT:     </dict>
     61 // CHECK-NEXT:     <key>ranges</key>
     62 // CHECK-NEXT:     <array>
     63 // CHECK-NEXT:       <array>
     64 // CHECK-NEXT:        <dict>
     65 // CHECK-NEXT:         <key>line</key><integer>7</integer>
     66 // CHECK-NEXT:         <key>col</key><integer>12</integer>
     67 // CHECK-NEXT:         <key>file</key><integer>0</integer>
     68 // CHECK-NEXT:        </dict>
     69 // CHECK-NEXT:        <dict>
     70 // CHECK-NEXT:         <key>line</key><integer>7</integer>
     71 // CHECK-NEXT:         <key>col</key><integer>21</integer>
     72 // CHECK-NEXT:         <key>file</key><integer>0</integer>
     73 // CHECK-NEXT:        </dict>
     74 // CHECK-NEXT:       </array>
     75 // CHECK-NEXT:     </array>
     76 // CHECK-NEXT:     <key>depth</key><integer>0</integer>
     77 // CHECK-NEXT:     <key>extended_message</key>
     78 // CHECK-NEXT:     <string>Memory is allocated</string>
     79 // CHECK-NEXT:     <key>message</key>
     80 // CHECK-NEXT:     <string>Memory is allocated</string>
     81 // CHECK-NEXT:    </dict>
     82 // CHECK-NEXT:    <dict>
     83 // CHECK-NEXT:     <key>kind</key><string>control</string>
     84 // CHECK-NEXT:     <key>edges</key>
     85 // CHECK-NEXT:      <array>
     86 // CHECK-NEXT:       <dict>
     87 // CHECK-NEXT:        <key>start</key>
     88 // CHECK-NEXT:         <array>
     89 // CHECK-NEXT:          <dict>
     90 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     91 // CHECK-NEXT:           <key>col</key><integer>12</integer>
     92 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     93 // CHECK-NEXT:          </dict>
     94 // CHECK-NEXT:          <dict>
     95 // CHECK-NEXT:           <key>line</key><integer>7</integer>
     96 // CHECK-NEXT:           <key>col</key><integer>14</integer>
     97 // CHECK-NEXT:           <key>file</key><integer>0</integer>
     98 // CHECK-NEXT:          </dict>
     99 // CHECK-NEXT:         </array>
    100 // CHECK-NEXT:        <key>end</key>
    101 // CHECK-NEXT:         <array>
    102 // CHECK-NEXT:          <dict>
    103 // CHECK-NEXT:           <key>line</key><integer>10</integer>
    104 // CHECK-NEXT:           <key>col</key><integer>3</integer>
    105 // CHECK-NEXT:           <key>file</key><integer>0</integer>
    106 // CHECK-NEXT:          </dict>
    107 // CHECK-NEXT:          <dict>
    108 // CHECK-NEXT:           <key>line</key><integer>10</integer>
    109 // CHECK-NEXT:           <key>col</key><integer>8</integer>
    110 // CHECK-NEXT:           <key>file</key><integer>0</integer>
    111 // CHECK-NEXT:          </dict>
    112 // CHECK-NEXT:         </array>
    113 // CHECK-NEXT:       </dict>
    114 // CHECK-NEXT:      </array>
    115 // CHECK-NEXT:    </dict>
    116 // CHECK-NEXT:    <dict>
    117 // CHECK-NEXT:     <key>kind</key><string>event</string>
    118 // CHECK-NEXT:     <key>location</key>
    119 // CHECK-NEXT:     <dict>
    120 // CHECK-NEXT:      <key>line</key><integer>10</integer>
    121 // CHECK-NEXT:      <key>col</key><integer>3</integer>
    122 // CHECK-NEXT:      <key>file</key><integer>0</integer>
    123 // CHECK-NEXT:     </dict>
    124 // CHECK-NEXT:     <key>ranges</key>
    125 // CHECK-NEXT:     <array>
    126 // CHECK-NEXT:       <array>
    127 // CHECK-NEXT:        <dict>
    128 // CHECK-NEXT:         <key>line</key><integer>10</integer>
    129 // CHECK-NEXT:         <key>col</key><integer>10</integer>
    130 // CHECK-NEXT:         <key>file</key><integer>0</integer>
    131 // CHECK-NEXT:        </dict>
    132 // CHECK-NEXT:        <dict>
    133 // CHECK-NEXT:         <key>line</key><integer>10</integer>
    134 // CHECK-NEXT:         <key>col</key><integer>10</integer>
    135 // CHECK-NEXT:         <key>file</key><integer>0</integer>
    136 // CHECK-NEXT:        </dict>
    137 // CHECK-NEXT:       </array>
    138 // CHECK-NEXT:     </array>
    139 // CHECK-NEXT:     <key>depth</key><integer>0</integer>
    140 // CHECK-NEXT:     <key>extended_message</key>
    141 // CHECK-NEXT:     <string>Memory allocated by &apos;new[]&apos; should be deallocated by &apos;delete[]&apos;, not &apos;delete&apos;</string>
    142 // CHECK-NEXT:     <key>message</key>
    143 // CHECK-NEXT:     <string>Memory allocated by &apos;new[]&apos; should be deallocated by &apos;delete[]&apos;, not &apos;delete&apos;</string>
    144 // CHECK-NEXT:    </dict>
    145 // CHECK-NEXT:   </array>
    146 // CHECK-NEXT:   <key>description</key><string>Memory allocated by &apos;new[]&apos; should be deallocated by &apos;delete[]&apos;, not &apos;delete&apos;</string>
    147 // CHECK-NEXT:   <key>category</key><string>Memory Error</string>
    148 // CHECK-NEXT:   <key>type</key><string>Bad deallocator</string>
    149 // CHECK-NEXT:  <key>issue_context_kind</key><string>function</string>
    150 // CHECK-NEXT:  <key>issue_context</key><string>test</string>
    151 // CHECK-NEXT:  <key>issue_hash</key><string>4</string>
    152 // CHECK-NEXT:  <key>location</key>
    153 // CHECK-NEXT:  <dict>
    154 // CHECK-NEXT:   <key>line</key><integer>10</integer>
    155 // CHECK-NEXT:   <key>col</key><integer>3</integer>
    156 // CHECK-NEXT:   <key>file</key><integer>0</integer>
    157 // CHECK-NEXT:  </dict>
    158 // CHECK-NEXT:  </dict>
    159 // CHECK-NEXT: </array>
    160