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 int *allocIntArray(unsigned c) { 7 return new int[c]; // expected-note {{Memory is allocated}} 8 } 9 void test() { 10 int *p = allocIntArray(1); // expected-note {{Calling 'allocIntArray'}} 11 // expected-note@-1 {{Returned allocated memory}} 12 changePointee(p); 13 delete p; // expected-warning {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}} 14 // expected-note@-1 {{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}} 15 } 16 17 // CHECK: <key>diagnostics</key> 18 // CHECK-NEXT: <array> 19 // CHECK-NEXT: <dict> 20 // CHECK-NEXT: <key>path</key> 21 // CHECK-NEXT: <array> 22 // CHECK-NEXT: <dict> 23 // CHECK-NEXT: <key>kind</key><string>control</string> 24 // CHECK-NEXT: <key>edges</key> 25 // CHECK-NEXT: <array> 26 // CHECK-NEXT: <dict> 27 // CHECK-NEXT: <key>start</key> 28 // CHECK-NEXT: <array> 29 // CHECK-NEXT: <dict> 30 // CHECK-NEXT: <key>line</key><integer>10</integer> 31 // CHECK-NEXT: <key>col</key><integer>3</integer> 32 // CHECK-NEXT: <key>file</key><integer>0</integer> 33 // CHECK-NEXT: </dict> 34 // CHECK-NEXT: <dict> 35 // CHECK-NEXT: <key>line</key><integer>10</integer> 36 // CHECK-NEXT: <key>col</key><integer>5</integer> 37 // CHECK-NEXT: <key>file</key><integer>0</integer> 38 // CHECK-NEXT: </dict> 39 // CHECK-NEXT: </array> 40 // CHECK-NEXT: <key>end</key> 41 // CHECK-NEXT: <array> 42 // CHECK-NEXT: <dict> 43 // CHECK-NEXT: <key>line</key><integer>10</integer> 44 // CHECK-NEXT: <key>col</key><integer>12</integer> 45 // CHECK-NEXT: <key>file</key><integer>0</integer> 46 // CHECK-NEXT: </dict> 47 // CHECK-NEXT: <dict> 48 // CHECK-NEXT: <key>line</key><integer>10</integer> 49 // CHECK-NEXT: <key>col</key><integer>24</integer> 50 // CHECK-NEXT: <key>file</key><integer>0</integer> 51 // CHECK-NEXT: </dict> 52 // CHECK-NEXT: </array> 53 // CHECK-NEXT: </dict> 54 // CHECK-NEXT: </array> 55 // CHECK-NEXT: </dict> 56 // CHECK-NEXT: <dict> 57 // CHECK-NEXT: <key>kind</key><string>event</string> 58 // CHECK-NEXT: <key>location</key> 59 // CHECK-NEXT: <dict> 60 // CHECK-NEXT: <key>line</key><integer>10</integer> 61 // CHECK-NEXT: <key>col</key><integer>12</integer> 62 // CHECK-NEXT: <key>file</key><integer>0</integer> 63 // CHECK-NEXT: </dict> 64 // CHECK-NEXT: <key>ranges</key> 65 // CHECK-NEXT: <array> 66 // CHECK-NEXT: <array> 67 // CHECK-NEXT: <dict> 68 // CHECK-NEXT: <key>line</key><integer>10</integer> 69 // CHECK-NEXT: <key>col</key><integer>12</integer> 70 // CHECK-NEXT: <key>file</key><integer>0</integer> 71 // CHECK-NEXT: </dict> 72 // CHECK-NEXT: <dict> 73 // CHECK-NEXT: <key>line</key><integer>10</integer> 74 // CHECK-NEXT: <key>col</key><integer>27</integer> 75 // CHECK-NEXT: <key>file</key><integer>0</integer> 76 // CHECK-NEXT: </dict> 77 // CHECK-NEXT: </array> 78 // CHECK-NEXT: </array> 79 // CHECK-NEXT: <key>depth</key><integer>0</integer> 80 // CHECK-NEXT: <key>extended_message</key> 81 // CHECK-NEXT: <string>Calling 'allocIntArray'</string> 82 // CHECK-NEXT: <key>message</key> 83 // CHECK-NEXT: <string>Calling 'allocIntArray'</string> 84 // CHECK-NEXT: </dict> 85 // CHECK-NEXT: <dict> 86 // CHECK-NEXT: <key>kind</key><string>event</string> 87 // CHECK-NEXT: <key>location</key> 88 // CHECK-NEXT: <dict> 89 // CHECK-NEXT: <key>line</key><integer>6</integer> 90 // CHECK-NEXT: <key>col</key><integer>1</integer> 91 // CHECK-NEXT: <key>file</key><integer>0</integer> 92 // CHECK-NEXT: </dict> 93 // CHECK-NEXT: <key>depth</key><integer>1</integer> 94 // CHECK-NEXT: <key>extended_message</key> 95 // CHECK-NEXT: <string>Entered call from 'test'</string> 96 // CHECK-NEXT: <key>message</key> 97 // CHECK-NEXT: <string>Entered call from 'test'</string> 98 // CHECK-NEXT: </dict> 99 // CHECK-NEXT: <dict> 100 // CHECK-NEXT: <key>kind</key><string>control</string> 101 // CHECK-NEXT: <key>edges</key> 102 // CHECK-NEXT: <array> 103 // CHECK-NEXT: <dict> 104 // CHECK-NEXT: <key>start</key> 105 // CHECK-NEXT: <array> 106 // CHECK-NEXT: <dict> 107 // CHECK-NEXT: <key>line</key><integer>6</integer> 108 // CHECK-NEXT: <key>col</key><integer>1</integer> 109 // CHECK-NEXT: <key>file</key><integer>0</integer> 110 // CHECK-NEXT: </dict> 111 // CHECK-NEXT: <dict> 112 // CHECK-NEXT: <key>line</key><integer>6</integer> 113 // CHECK-NEXT: <key>col</key><integer>3</integer> 114 // CHECK-NEXT: <key>file</key><integer>0</integer> 115 // CHECK-NEXT: </dict> 116 // CHECK-NEXT: </array> 117 // CHECK-NEXT: <key>end</key> 118 // CHECK-NEXT: <array> 119 // CHECK-NEXT: <dict> 120 // CHECK-NEXT: <key>line</key><integer>7</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: <dict> 125 // CHECK-NEXT: <key>line</key><integer>7</integer> 126 // CHECK-NEXT: <key>col</key><integer>8</integer> 127 // CHECK-NEXT: <key>file</key><integer>0</integer> 128 // CHECK-NEXT: </dict> 129 // CHECK-NEXT: </array> 130 // CHECK-NEXT: </dict> 131 // CHECK-NEXT: </array> 132 // CHECK-NEXT: </dict> 133 // CHECK-NEXT: <dict> 134 // CHECK-NEXT: <key>kind</key><string>control</string> 135 // CHECK-NEXT: <key>edges</key> 136 // CHECK-NEXT: <array> 137 // CHECK-NEXT: <dict> 138 // CHECK-NEXT: <key>start</key> 139 // CHECK-NEXT: <array> 140 // CHECK-NEXT: <dict> 141 // CHECK-NEXT: <key>line</key><integer>7</integer> 142 // CHECK-NEXT: <key>col</key><integer>3</integer> 143 // CHECK-NEXT: <key>file</key><integer>0</integer> 144 // CHECK-NEXT: </dict> 145 // CHECK-NEXT: <dict> 146 // CHECK-NEXT: <key>line</key><integer>7</integer> 147 // CHECK-NEXT: <key>col</key><integer>8</integer> 148 // CHECK-NEXT: <key>file</key><integer>0</integer> 149 // CHECK-NEXT: </dict> 150 // CHECK-NEXT: </array> 151 // CHECK-NEXT: <key>end</key> 152 // CHECK-NEXT: <array> 153 // CHECK-NEXT: <dict> 154 // CHECK-NEXT: <key>line</key><integer>7</integer> 155 // CHECK-NEXT: <key>col</key><integer>10</integer> 156 // CHECK-NEXT: <key>file</key><integer>0</integer> 157 // CHECK-NEXT: </dict> 158 // CHECK-NEXT: <dict> 159 // CHECK-NEXT: <key>line</key><integer>7</integer> 160 // CHECK-NEXT: <key>col</key><integer>12</integer> 161 // CHECK-NEXT: <key>file</key><integer>0</integer> 162 // CHECK-NEXT: </dict> 163 // CHECK-NEXT: </array> 164 // CHECK-NEXT: </dict> 165 // CHECK-NEXT: </array> 166 // CHECK-NEXT: </dict> 167 // CHECK-NEXT: <dict> 168 // CHECK-NEXT: <key>kind</key><string>event</string> 169 // CHECK-NEXT: <key>location</key> 170 // CHECK-NEXT: <dict> 171 // CHECK-NEXT: <key>line</key><integer>7</integer> 172 // CHECK-NEXT: <key>col</key><integer>10</integer> 173 // CHECK-NEXT: <key>file</key><integer>0</integer> 174 // CHECK-NEXT: </dict> 175 // CHECK-NEXT: <key>ranges</key> 176 // CHECK-NEXT: <array> 177 // CHECK-NEXT: <array> 178 // CHECK-NEXT: <dict> 179 // CHECK-NEXT: <key>line</key><integer>7</integer> 180 // CHECK-NEXT: <key>col</key><integer>10</integer> 181 // CHECK-NEXT: <key>file</key><integer>0</integer> 182 // CHECK-NEXT: </dict> 183 // CHECK-NEXT: <dict> 184 // CHECK-NEXT: <key>line</key><integer>7</integer> 185 // CHECK-NEXT: <key>col</key><integer>19</integer> 186 // CHECK-NEXT: <key>file</key><integer>0</integer> 187 // CHECK-NEXT: </dict> 188 // CHECK-NEXT: </array> 189 // CHECK-NEXT: </array> 190 // CHECK-NEXT: <key>depth</key><integer>1</integer> 191 // CHECK-NEXT: <key>extended_message</key> 192 // CHECK-NEXT: <string>Memory is allocated</string> 193 // CHECK-NEXT: <key>message</key> 194 // CHECK-NEXT: <string>Memory is allocated</string> 195 // CHECK-NEXT: </dict> 196 // CHECK-NEXT: <dict> 197 // CHECK-NEXT: <key>kind</key><string>event</string> 198 // CHECK-NEXT: <key>location</key> 199 // CHECK-NEXT: <dict> 200 // CHECK-NEXT: <key>line</key><integer>10</integer> 201 // CHECK-NEXT: <key>col</key><integer>12</integer> 202 // CHECK-NEXT: <key>file</key><integer>0</integer> 203 // CHECK-NEXT: </dict> 204 // CHECK-NEXT: <key>ranges</key> 205 // CHECK-NEXT: <array> 206 // CHECK-NEXT: <array> 207 // CHECK-NEXT: <dict> 208 // CHECK-NEXT: <key>line</key><integer>10</integer> 209 // CHECK-NEXT: <key>col</key><integer>12</integer> 210 // CHECK-NEXT: <key>file</key><integer>0</integer> 211 // CHECK-NEXT: </dict> 212 // CHECK-NEXT: <dict> 213 // CHECK-NEXT: <key>line</key><integer>10</integer> 214 // CHECK-NEXT: <key>col</key><integer>27</integer> 215 // CHECK-NEXT: <key>file</key><integer>0</integer> 216 // CHECK-NEXT: </dict> 217 // CHECK-NEXT: </array> 218 // CHECK-NEXT: </array> 219 // CHECK-NEXT: <key>depth</key><integer>0</integer> 220 // CHECK-NEXT: <key>extended_message</key> 221 // CHECK-NEXT: <string>Returned allocated memory</string> 222 // CHECK-NEXT: <key>message</key> 223 // CHECK-NEXT: <string>Returned allocated memory</string> 224 // CHECK-NEXT: </dict> 225 // CHECK-NEXT: <dict> 226 // CHECK-NEXT: <key>kind</key><string>control</string> 227 // CHECK-NEXT: <key>edges</key> 228 // CHECK-NEXT: <array> 229 // CHECK-NEXT: <dict> 230 // CHECK-NEXT: <key>start</key> 231 // CHECK-NEXT: <array> 232 // CHECK-NEXT: <dict> 233 // CHECK-NEXT: <key>line</key><integer>10</integer> 234 // CHECK-NEXT: <key>col</key><integer>12</integer> 235 // CHECK-NEXT: <key>file</key><integer>0</integer> 236 // CHECK-NEXT: </dict> 237 // CHECK-NEXT: <dict> 238 // CHECK-NEXT: <key>line</key><integer>10</integer> 239 // CHECK-NEXT: <key>col</key><integer>24</integer> 240 // CHECK-NEXT: <key>file</key><integer>0</integer> 241 // CHECK-NEXT: </dict> 242 // CHECK-NEXT: </array> 243 // CHECK-NEXT: <key>end</key> 244 // CHECK-NEXT: <array> 245 // CHECK-NEXT: <dict> 246 // CHECK-NEXT: <key>line</key><integer>13</integer> 247 // CHECK-NEXT: <key>col</key><integer>3</integer> 248 // CHECK-NEXT: <key>file</key><integer>0</integer> 249 // CHECK-NEXT: </dict> 250 // CHECK-NEXT: <dict> 251 // CHECK-NEXT: <key>line</key><integer>13</integer> 252 // CHECK-NEXT: <key>col</key><integer>8</integer> 253 // CHECK-NEXT: <key>file</key><integer>0</integer> 254 // CHECK-NEXT: </dict> 255 // CHECK-NEXT: </array> 256 // CHECK-NEXT: </dict> 257 // CHECK-NEXT: </array> 258 // CHECK-NEXT: </dict> 259 // CHECK-NEXT: <dict> 260 // CHECK-NEXT: <key>kind</key><string>event</string> 261 // CHECK-NEXT: <key>location</key> 262 // CHECK-NEXT: <dict> 263 // CHECK-NEXT: <key>line</key><integer>13</integer> 264 // CHECK-NEXT: <key>col</key><integer>3</integer> 265 // CHECK-NEXT: <key>file</key><integer>0</integer> 266 // CHECK-NEXT: </dict> 267 // CHECK-NEXT: <key>ranges</key> 268 // CHECK-NEXT: <array> 269 // CHECK-NEXT: <array> 270 // CHECK-NEXT: <dict> 271 // CHECK-NEXT: <key>line</key><integer>13</integer> 272 // CHECK-NEXT: <key>col</key><integer>10</integer> 273 // CHECK-NEXT: <key>file</key><integer>0</integer> 274 // CHECK-NEXT: </dict> 275 // CHECK-NEXT: <dict> 276 // CHECK-NEXT: <key>line</key><integer>13</integer> 277 // CHECK-NEXT: <key>col</key><integer>10</integer> 278 // CHECK-NEXT: <key>file</key><integer>0</integer> 279 // CHECK-NEXT: </dict> 280 // CHECK-NEXT: </array> 281 // CHECK-NEXT: </array> 282 // CHECK-NEXT: <key>depth</key><integer>0</integer> 283 // CHECK-NEXT: <key>extended_message</key> 284 // CHECK-NEXT: <string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string> 285 // CHECK-NEXT: <key>message</key> 286 // CHECK-NEXT: <string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string> 287 // CHECK-NEXT: </dict> 288 // CHECK-NEXT: </array> 289 // CHECK-NEXT: <key>description</key><string>Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'</string> 290 // CHECK-NEXT: <key>category</key><string>Memory Error</string> 291 // CHECK-NEXT: <key>type</key><string>Bad deallocator</string> 292 // CHECK-NEXT: <key>check_name</key><string>unix.MismatchedDeallocator</string> 293 // CHECK-NEXT: <!-- This hash is experimental and going to change! --> 294 // CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>2009ca1da75217064b6052ba7465dff9</string> 295 // CHECK-NEXT: <key>issue_context_kind</key><string>function</string> 296 // CHECK-NEXT: <key>issue_context</key><string>test</string> 297 // CHECK-NEXT: <key>issue_hash_function_offset</key><string>4</string> 298 // CHECK-NEXT: <key>location</key> 299 // CHECK-NEXT: <dict> 300 // CHECK-NEXT: <key>line</key><integer>13</integer> 301 // CHECK-NEXT: <key>col</key><integer>3</integer> 302 // CHECK-NEXT: <key>file</key><integer>0</integer> 303 // CHECK-NEXT: </dict> 304 // CHECK-NEXT: </dict> 305 // CHECK-NEXT: </array> 306