1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=text -analyzer-config graph-trim-interval=5 -analyzer-config suppress-null-return-paths=false -verify %s 2 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=plist-multi-file -analyzer-config graph-trim-interval=5 -analyzer-config suppress-null-return-paths=false -analyzer-config path-diagnostics-alternate=false %s -o %t.plist 3 // RUN: FileCheck --input-file=%t.plist %s 4 5 typedef struct { 6 int getValue(); 7 } IntWrapper; 8 9 IntWrapper *getNullWrapper() { 10 return 0; 11 // expected-note@-1 {{Returning null pointer}} 12 } 13 14 int memberCallBaseDisappears() { 15 // In this case, we need the lvalue-to-rvalue cast for 'ptr' to disappear, 16 // which means we need to trigger reclamation between that and the -> 17 // operator. 18 // 19 // Note that this test is EXTREMELY brittle because it's a negative test: 20 // we want to show that even if the node for the rvalue of 'ptr' disappears, 21 // we get the same results as if it doesn't. The test should never fail even 22 // if our node reclamation policy changes, but it could easily not be testing 23 // anything at that point. 24 IntWrapper *ptr = getNullWrapper(); 25 // expected-note@-1 {{Calling 'getNullWrapper'}} 26 // expected-note@-2 {{Returning from 'getNullWrapper'}} 27 // expected-note@-3 {{'ptr' initialized to a null pointer value}} 28 29 // Burn some nodes to trigger reclamation. 30 int unused = 1; 31 (void)unused; 32 33 return ptr->getValue(); // expected-warning {{Called C++ object pointer is null}} 34 // expected-note@-1 {{Called C++ object pointer is null}} 35 } 36 37 // CHECK: <key>diagnostics</key> 38 // CHECK-NEXT: <array> 39 // CHECK-NEXT: <dict> 40 // CHECK-NEXT: <key>path</key> 41 // CHECK-NEXT: <array> 42 // CHECK-NEXT: <dict> 43 // CHECK-NEXT: <key>kind</key><string>control</string> 44 // CHECK-NEXT: <key>edges</key> 45 // CHECK-NEXT: <array> 46 // CHECK-NEXT: <dict> 47 // CHECK-NEXT: <key>start</key> 48 // CHECK-NEXT: <array> 49 // CHECK-NEXT: <dict> 50 // CHECK-NEXT: <key>line</key><integer>24</integer> 51 // CHECK-NEXT: <key>col</key><integer>3</integer> 52 // CHECK-NEXT: <key>file</key><integer>0</integer> 53 // CHECK-NEXT: </dict> 54 // CHECK-NEXT: <dict> 55 // CHECK-NEXT: <key>line</key><integer>24</integer> 56 // CHECK-NEXT: <key>col</key><integer>12</integer> 57 // CHECK-NEXT: <key>file</key><integer>0</integer> 58 // CHECK-NEXT: </dict> 59 // CHECK-NEXT: </array> 60 // CHECK-NEXT: <key>end</key> 61 // CHECK-NEXT: <array> 62 // CHECK-NEXT: <dict> 63 // CHECK-NEXT: <key>line</key><integer>24</integer> 64 // CHECK-NEXT: <key>col</key><integer>21</integer> 65 // CHECK-NEXT: <key>file</key><integer>0</integer> 66 // CHECK-NEXT: </dict> 67 // CHECK-NEXT: <dict> 68 // CHECK-NEXT: <key>line</key><integer>24</integer> 69 // CHECK-NEXT: <key>col</key><integer>34</integer> 70 // CHECK-NEXT: <key>file</key><integer>0</integer> 71 // CHECK-NEXT: </dict> 72 // CHECK-NEXT: </array> 73 // CHECK-NEXT: </dict> 74 // CHECK-NEXT: </array> 75 // CHECK-NEXT: </dict> 76 // CHECK-NEXT: <dict> 77 // CHECK-NEXT: <key>kind</key><string>event</string> 78 // CHECK-NEXT: <key>location</key> 79 // CHECK-NEXT: <dict> 80 // CHECK-NEXT: <key>line</key><integer>24</integer> 81 // CHECK-NEXT: <key>col</key><integer>21</integer> 82 // CHECK-NEXT: <key>file</key><integer>0</integer> 83 // CHECK-NEXT: </dict> 84 // CHECK-NEXT: <key>ranges</key> 85 // CHECK-NEXT: <array> 86 // CHECK-NEXT: <array> 87 // CHECK-NEXT: <dict> 88 // CHECK-NEXT: <key>line</key><integer>24</integer> 89 // CHECK-NEXT: <key>col</key><integer>21</integer> 90 // CHECK-NEXT: <key>file</key><integer>0</integer> 91 // CHECK-NEXT: </dict> 92 // CHECK-NEXT: <dict> 93 // CHECK-NEXT: <key>line</key><integer>24</integer> 94 // CHECK-NEXT: <key>col</key><integer>36</integer> 95 // CHECK-NEXT: <key>file</key><integer>0</integer> 96 // CHECK-NEXT: </dict> 97 // CHECK-NEXT: </array> 98 // CHECK-NEXT: </array> 99 // CHECK-NEXT: <key>depth</key><integer>0</integer> 100 // CHECK-NEXT: <key>extended_message</key> 101 // CHECK-NEXT: <string>Calling 'getNullWrapper'</string> 102 // CHECK-NEXT: <key>message</key> 103 // CHECK-NEXT: <string>Calling 'getNullWrapper'</string> 104 // CHECK-NEXT: </dict> 105 // CHECK-NEXT: <dict> 106 // CHECK-NEXT: <key>kind</key><string>event</string> 107 // CHECK-NEXT: <key>location</key> 108 // CHECK-NEXT: <dict> 109 // CHECK-NEXT: <key>line</key><integer>9</integer> 110 // CHECK-NEXT: <key>col</key><integer>1</integer> 111 // CHECK-NEXT: <key>file</key><integer>0</integer> 112 // CHECK-NEXT: </dict> 113 // CHECK-NEXT: <key>depth</key><integer>1</integer> 114 // CHECK-NEXT: <key>extended_message</key> 115 // CHECK-NEXT: <string>Entered call from 'memberCallBaseDisappears'</string> 116 // CHECK-NEXT: <key>message</key> 117 // CHECK-NEXT: <string>Entered call from 'memberCallBaseDisappears'</string> 118 // CHECK-NEXT: </dict> 119 // CHECK-NEXT: <dict> 120 // CHECK-NEXT: <key>kind</key><string>control</string> 121 // CHECK-NEXT: <key>edges</key> 122 // CHECK-NEXT: <array> 123 // CHECK-NEXT: <dict> 124 // CHECK-NEXT: <key>start</key> 125 // CHECK-NEXT: <array> 126 // CHECK-NEXT: <dict> 127 // CHECK-NEXT: <key>line</key><integer>9</integer> 128 // CHECK-NEXT: <key>col</key><integer>1</integer> 129 // CHECK-NEXT: <key>file</key><integer>0</integer> 130 // CHECK-NEXT: </dict> 131 // CHECK-NEXT: <dict> 132 // CHECK-NEXT: <key>line</key><integer>9</integer> 133 // CHECK-NEXT: <key>col</key><integer>10</integer> 134 // CHECK-NEXT: <key>file</key><integer>0</integer> 135 // CHECK-NEXT: </dict> 136 // CHECK-NEXT: </array> 137 // CHECK-NEXT: <key>end</key> 138 // CHECK-NEXT: <array> 139 // CHECK-NEXT: <dict> 140 // CHECK-NEXT: <key>line</key><integer>10</integer> 141 // CHECK-NEXT: <key>col</key><integer>3</integer> 142 // CHECK-NEXT: <key>file</key><integer>0</integer> 143 // CHECK-NEXT: </dict> 144 // CHECK-NEXT: <dict> 145 // CHECK-NEXT: <key>line</key><integer>10</integer> 146 // CHECK-NEXT: <key>col</key><integer>8</integer> 147 // CHECK-NEXT: <key>file</key><integer>0</integer> 148 // CHECK-NEXT: </dict> 149 // CHECK-NEXT: </array> 150 // CHECK-NEXT: </dict> 151 // CHECK-NEXT: </array> 152 // CHECK-NEXT: </dict> 153 // CHECK-NEXT: <dict> 154 // CHECK-NEXT: <key>kind</key><string>event</string> 155 // CHECK-NEXT: <key>location</key> 156 // CHECK-NEXT: <dict> 157 // CHECK-NEXT: <key>line</key><integer>10</integer> 158 // CHECK-NEXT: <key>col</key><integer>3</integer> 159 // CHECK-NEXT: <key>file</key><integer>0</integer> 160 // CHECK-NEXT: </dict> 161 // CHECK-NEXT: <key>ranges</key> 162 // CHECK-NEXT: <array> 163 // CHECK-NEXT: <array> 164 // CHECK-NEXT: <dict> 165 // CHECK-NEXT: <key>line</key><integer>10</integer> 166 // CHECK-NEXT: <key>col</key><integer>3</integer> 167 // CHECK-NEXT: <key>file</key><integer>0</integer> 168 // CHECK-NEXT: </dict> 169 // CHECK-NEXT: <dict> 170 // CHECK-NEXT: <key>line</key><integer>10</integer> 171 // CHECK-NEXT: <key>col</key><integer>10</integer> 172 // CHECK-NEXT: <key>file</key><integer>0</integer> 173 // CHECK-NEXT: </dict> 174 // CHECK-NEXT: </array> 175 // CHECK-NEXT: </array> 176 // CHECK-NEXT: <key>depth</key><integer>1</integer> 177 // CHECK-NEXT: <key>extended_message</key> 178 // CHECK-NEXT: <string>Returning null pointer</string> 179 // CHECK-NEXT: <key>message</key> 180 // CHECK-NEXT: <string>Returning null pointer</string> 181 // CHECK-NEXT: </dict> 182 // CHECK-NEXT: <dict> 183 // CHECK-NEXT: <key>kind</key><string>event</string> 184 // CHECK-NEXT: <key>location</key> 185 // CHECK-NEXT: <dict> 186 // CHECK-NEXT: <key>line</key><integer>24</integer> 187 // CHECK-NEXT: <key>col</key><integer>21</integer> 188 // CHECK-NEXT: <key>file</key><integer>0</integer> 189 // CHECK-NEXT: </dict> 190 // CHECK-NEXT: <key>ranges</key> 191 // CHECK-NEXT: <array> 192 // CHECK-NEXT: <array> 193 // CHECK-NEXT: <dict> 194 // CHECK-NEXT: <key>line</key><integer>24</integer> 195 // CHECK-NEXT: <key>col</key><integer>21</integer> 196 // CHECK-NEXT: <key>file</key><integer>0</integer> 197 // CHECK-NEXT: </dict> 198 // CHECK-NEXT: <dict> 199 // CHECK-NEXT: <key>line</key><integer>24</integer> 200 // CHECK-NEXT: <key>col</key><integer>36</integer> 201 // CHECK-NEXT: <key>file</key><integer>0</integer> 202 // CHECK-NEXT: </dict> 203 // CHECK-NEXT: </array> 204 // CHECK-NEXT: </array> 205 // CHECK-NEXT: <key>depth</key><integer>0</integer> 206 // CHECK-NEXT: <key>extended_message</key> 207 // CHECK-NEXT: <string>Returning from 'getNullWrapper'</string> 208 // CHECK-NEXT: <key>message</key> 209 // CHECK-NEXT: <string>Returning from 'getNullWrapper'</string> 210 // CHECK-NEXT: </dict> 211 // CHECK-NEXT: <dict> 212 // CHECK-NEXT: <key>kind</key><string>control</string> 213 // CHECK-NEXT: <key>edges</key> 214 // CHECK-NEXT: <array> 215 // CHECK-NEXT: <dict> 216 // CHECK-NEXT: <key>start</key> 217 // CHECK-NEXT: <array> 218 // CHECK-NEXT: <dict> 219 // CHECK-NEXT: <key>line</key><integer>24</integer> 220 // CHECK-NEXT: <key>col</key><integer>21</integer> 221 // CHECK-NEXT: <key>file</key><integer>0</integer> 222 // CHECK-NEXT: </dict> 223 // CHECK-NEXT: <dict> 224 // CHECK-NEXT: <key>line</key><integer>24</integer> 225 // CHECK-NEXT: <key>col</key><integer>34</integer> 226 // CHECK-NEXT: <key>file</key><integer>0</integer> 227 // CHECK-NEXT: </dict> 228 // CHECK-NEXT: </array> 229 // CHECK-NEXT: <key>end</key> 230 // CHECK-NEXT: <array> 231 // CHECK-NEXT: <dict> 232 // CHECK-NEXT: <key>line</key><integer>24</integer> 233 // CHECK-NEXT: <key>col</key><integer>3</integer> 234 // CHECK-NEXT: <key>file</key><integer>0</integer> 235 // CHECK-NEXT: </dict> 236 // CHECK-NEXT: <dict> 237 // CHECK-NEXT: <key>line</key><integer>24</integer> 238 // CHECK-NEXT: <key>col</key><integer>12</integer> 239 // CHECK-NEXT: <key>file</key><integer>0</integer> 240 // CHECK-NEXT: </dict> 241 // CHECK-NEXT: </array> 242 // CHECK-NEXT: </dict> 243 // CHECK-NEXT: </array> 244 // CHECK-NEXT: </dict> 245 // CHECK-NEXT: <dict> 246 // CHECK-NEXT: <key>kind</key><string>event</string> 247 // CHECK-NEXT: <key>location</key> 248 // CHECK-NEXT: <dict> 249 // CHECK-NEXT: <key>line</key><integer>24</integer> 250 // CHECK-NEXT: <key>col</key><integer>3</integer> 251 // CHECK-NEXT: <key>file</key><integer>0</integer> 252 // CHECK-NEXT: </dict> 253 // CHECK-NEXT: <key>ranges</key> 254 // CHECK-NEXT: <array> 255 // CHECK-NEXT: <array> 256 // CHECK-NEXT: <dict> 257 // CHECK-NEXT: <key>line</key><integer>24</integer> 258 // CHECK-NEXT: <key>col</key><integer>3</integer> 259 // CHECK-NEXT: <key>file</key><integer>0</integer> 260 // CHECK-NEXT: </dict> 261 // CHECK-NEXT: <dict> 262 // CHECK-NEXT: <key>line</key><integer>24</integer> 263 // CHECK-NEXT: <key>col</key><integer>17</integer> 264 // CHECK-NEXT: <key>file</key><integer>0</integer> 265 // CHECK-NEXT: </dict> 266 // CHECK-NEXT: </array> 267 // CHECK-NEXT: </array> 268 // CHECK-NEXT: <key>depth</key><integer>0</integer> 269 // CHECK-NEXT: <key>extended_message</key> 270 // CHECK-NEXT: <string>'ptr' initialized to a null pointer value</string> 271 // CHECK-NEXT: <key>message</key> 272 // CHECK-NEXT: <string>'ptr' initialized to a null pointer value</string> 273 // CHECK-NEXT: </dict> 274 // CHECK-NEXT: <dict> 275 // CHECK-NEXT: <key>kind</key><string>control</string> 276 // CHECK-NEXT: <key>edges</key> 277 // CHECK-NEXT: <array> 278 // CHECK-NEXT: <dict> 279 // CHECK-NEXT: <key>start</key> 280 // CHECK-NEXT: <array> 281 // CHECK-NEXT: <dict> 282 // CHECK-NEXT: <key>line</key><integer>24</integer> 283 // CHECK-NEXT: <key>col</key><integer>3</integer> 284 // CHECK-NEXT: <key>file</key><integer>0</integer> 285 // CHECK-NEXT: </dict> 286 // CHECK-NEXT: <dict> 287 // CHECK-NEXT: <key>line</key><integer>24</integer> 288 // CHECK-NEXT: <key>col</key><integer>12</integer> 289 // CHECK-NEXT: <key>file</key><integer>0</integer> 290 // CHECK-NEXT: </dict> 291 // CHECK-NEXT: </array> 292 // CHECK-NEXT: <key>end</key> 293 // CHECK-NEXT: <array> 294 // CHECK-NEXT: <dict> 295 // CHECK-NEXT: <key>line</key><integer>33</integer> 296 // CHECK-NEXT: <key>col</key><integer>3</integer> 297 // CHECK-NEXT: <key>file</key><integer>0</integer> 298 // CHECK-NEXT: </dict> 299 // CHECK-NEXT: <dict> 300 // CHECK-NEXT: <key>line</key><integer>33</integer> 301 // CHECK-NEXT: <key>col</key><integer>8</integer> 302 // CHECK-NEXT: <key>file</key><integer>0</integer> 303 // CHECK-NEXT: </dict> 304 // CHECK-NEXT: </array> 305 // CHECK-NEXT: </dict> 306 // CHECK-NEXT: </array> 307 // CHECK-NEXT: </dict> 308 // CHECK-NEXT: <dict> 309 // CHECK-NEXT: <key>kind</key><string>control</string> 310 // CHECK-NEXT: <key>edges</key> 311 // CHECK-NEXT: <array> 312 // CHECK-NEXT: <dict> 313 // CHECK-NEXT: <key>start</key> 314 // CHECK-NEXT: <array> 315 // CHECK-NEXT: <dict> 316 // CHECK-NEXT: <key>line</key><integer>33</integer> 317 // CHECK-NEXT: <key>col</key><integer>3</integer> 318 // CHECK-NEXT: <key>file</key><integer>0</integer> 319 // CHECK-NEXT: </dict> 320 // CHECK-NEXT: <dict> 321 // CHECK-NEXT: <key>line</key><integer>33</integer> 322 // CHECK-NEXT: <key>col</key><integer>8</integer> 323 // CHECK-NEXT: <key>file</key><integer>0</integer> 324 // CHECK-NEXT: </dict> 325 // CHECK-NEXT: </array> 326 // CHECK-NEXT: <key>end</key> 327 // CHECK-NEXT: <array> 328 // CHECK-NEXT: <dict> 329 // CHECK-NEXT: <key>line</key><integer>33</integer> 330 // CHECK-NEXT: <key>col</key><integer>10</integer> 331 // CHECK-NEXT: <key>file</key><integer>0</integer> 332 // CHECK-NEXT: </dict> 333 // CHECK-NEXT: <dict> 334 // CHECK-NEXT: <key>line</key><integer>33</integer> 335 // CHECK-NEXT: <key>col</key><integer>12</integer> 336 // CHECK-NEXT: <key>file</key><integer>0</integer> 337 // CHECK-NEXT: </dict> 338 // CHECK-NEXT: </array> 339 // CHECK-NEXT: </dict> 340 // CHECK-NEXT: </array> 341 // CHECK-NEXT: </dict> 342 // CHECK-NEXT: <dict> 343 // CHECK-NEXT: <key>kind</key><string>event</string> 344 // CHECK-NEXT: <key>location</key> 345 // CHECK-NEXT: <dict> 346 // CHECK-NEXT: <key>line</key><integer>33</integer> 347 // CHECK-NEXT: <key>col</key><integer>10</integer> 348 // CHECK-NEXT: <key>file</key><integer>0</integer> 349 // CHECK-NEXT: </dict> 350 // CHECK-NEXT: <key>ranges</key> 351 // CHECK-NEXT: <array> 352 // CHECK-NEXT: <array> 353 // CHECK-NEXT: <dict> 354 // CHECK-NEXT: <key>line</key><integer>33</integer> 355 // CHECK-NEXT: <key>col</key><integer>10</integer> 356 // CHECK-NEXT: <key>file</key><integer>0</integer> 357 // CHECK-NEXT: </dict> 358 // CHECK-NEXT: <dict> 359 // CHECK-NEXT: <key>line</key><integer>33</integer> 360 // CHECK-NEXT: <key>col</key><integer>12</integer> 361 // CHECK-NEXT: <key>file</key><integer>0</integer> 362 // CHECK-NEXT: </dict> 363 // CHECK-NEXT: </array> 364 // CHECK-NEXT: </array> 365 // CHECK-NEXT: <key>depth</key><integer>0</integer> 366 // CHECK-NEXT: <key>extended_message</key> 367 // CHECK-NEXT: <string>Called C++ object pointer is null</string> 368 // CHECK-NEXT: <key>message</key> 369 // CHECK-NEXT: <string>Called C++ object pointer is null</string> 370 // CHECK-NEXT: </dict> 371 // CHECK-NEXT: </array> 372 // CHECK-NEXT: <key>description</key><string>Called C++ object pointer is null</string> 373 // CHECK-NEXT: <key>category</key><string>Logic error</string> 374 // CHECK-NEXT: <key>type</key><string>Called C++ object pointer is null</string> 375 // CHECK-NEXT: <key>issue_context_kind</key><string>function</string> 376 // CHECK-NEXT: <key>issue_context</key><string>memberCallBaseDisappears</string> 377 // CHECK-NEXT: <key>issue_hash</key><string>19</string> 378 // CHECK-NEXT: <key>location</key> 379 // CHECK-NEXT: <dict> 380 // CHECK-NEXT: <key>line</key><integer>33</integer> 381 // CHECK-NEXT: <key>col</key><integer>10</integer> 382 // CHECK-NEXT: <key>file</key><integer>0</integer> 383 // CHECK-NEXT: </dict> 384 // CHECK-NEXT: </dict> 385 // CHECK-NEXT: </array> 386