1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config faux-bodies=true,model-path=%S/Inputs/Models -analyzer-output=plist-multi-file -verify %s -o %t 2 // RUN: FileCheck --input-file=%t %s 3 4 typedef int* intptr; 5 6 // This function is modeled and the p pointer is dereferenced in the model 7 // function and there is no function definition available. The modeled 8 // function can use any types that are available in the original translation 9 // unit, for example intptr in this case. 10 void modeledFunction(intptr p); 11 12 // This function is modeled and returns true if the parameter is not zero 13 // and there is no function definition available. 14 bool notzero(int i); 15 16 // This functions is not modeled and there is no function definition. 17 // available 18 bool notzero_notmodeled(int i); 19 20 int main() { 21 // There is a nullpointer dereference inside this function. 22 modeledFunction(0); 23 24 int p = 0; 25 if (notzero(p)) { 26 // It is known that p != 0 because of the information provided by the 27 // model of the notzero function. 28 int j = 5 / p; 29 } 30 31 if (notzero_notmodeled(p)) { 32 // There is no information about the value of p, because 33 // notzero_notmodeled is not modeled and the function definition 34 // is not available. 35 int j = 5 / p; // expected-warning {{Division by zero}} 36 } 37 38 return 0; 39 } 40 41 // CHECK: <key>diagnostics</key> 42 // CHECK-NEXT: <array> 43 // CHECK-NEXT: <dict> 44 // CHECK-NEXT: <key>path</key> 45 // CHECK-NEXT: <array> 46 // CHECK-NEXT: <dict> 47 // CHECK-NEXT: <key>kind</key><string>control</string> 48 // CHECK-NEXT: <key>edges</key> 49 // CHECK-NEXT: <array> 50 // CHECK-NEXT: <dict> 51 // CHECK-NEXT: <key>start</key> 52 // CHECK-NEXT: <array> 53 // CHECK-NEXT: <dict> 54 // CHECK-NEXT: <key>line</key><integer>22</integer> 55 // CHECK-NEXT: <key>col</key><integer>3</integer> 56 // CHECK-NEXT: <key>file</key><integer>0</integer> 57 // CHECK-NEXT: </dict> 58 // CHECK-NEXT: <dict> 59 // CHECK-NEXT: <key>line</key><integer>22</integer> 60 // CHECK-NEXT: <key>col</key><integer>17</integer> 61 // CHECK-NEXT: <key>file</key><integer>0</integer> 62 // CHECK-NEXT: </dict> 63 // CHECK-NEXT: </array> 64 // CHECK-NEXT: <key>end</key> 65 // CHECK-NEXT: <array> 66 // CHECK-NEXT: <dict> 67 // CHECK-NEXT: <key>line</key><integer>24</integer> 68 // CHECK-NEXT: <key>col</key><integer>3</integer> 69 // CHECK-NEXT: <key>file</key><integer>0</integer> 70 // CHECK-NEXT: </dict> 71 // CHECK-NEXT: <dict> 72 // CHECK-NEXT: <key>line</key><integer>24</integer> 73 // CHECK-NEXT: <key>col</key><integer>5</integer> 74 // CHECK-NEXT: <key>file</key><integer>0</integer> 75 // CHECK-NEXT: </dict> 76 // CHECK-NEXT: </array> 77 // CHECK-NEXT: </dict> 78 // CHECK-NEXT: </array> 79 // CHECK-NEXT: </dict> 80 // CHECK-NEXT: <dict> 81 // CHECK-NEXT: <key>kind</key><string>event</string> 82 // CHECK-NEXT: <key>location</key> 83 // CHECK-NEXT: <dict> 84 // CHECK-NEXT: <key>line</key><integer>24</integer> 85 // CHECK-NEXT: <key>col</key><integer>3</integer> 86 // CHECK-NEXT: <key>file</key><integer>0</integer> 87 // CHECK-NEXT: </dict> 88 // CHECK-NEXT: <key>ranges</key> 89 // CHECK-NEXT: <array> 90 // CHECK-NEXT: <array> 91 // CHECK-NEXT: <dict> 92 // CHECK-NEXT: <key>line</key><integer>24</integer> 93 // CHECK-NEXT: <key>col</key><integer>3</integer> 94 // CHECK-NEXT: <key>file</key><integer>0</integer> 95 // CHECK-NEXT: </dict> 96 // CHECK-NEXT: <dict> 97 // CHECK-NEXT: <key>line</key><integer>24</integer> 98 // CHECK-NEXT: <key>col</key><integer>7</integer> 99 // CHECK-NEXT: <key>file</key><integer>0</integer> 100 // CHECK-NEXT: </dict> 101 // CHECK-NEXT: </array> 102 // CHECK-NEXT: </array> 103 // CHECK-NEXT: <key>depth</key><integer>0</integer> 104 // CHECK-NEXT: <key>extended_message</key> 105 // CHECK-NEXT: <string>'p' initialized to 0</string> 106 // CHECK-NEXT: <key>message</key> 107 // CHECK-NEXT: <string>'p' initialized to 0</string> 108 // CHECK-NEXT: </dict> 109 // CHECK-NEXT: <dict> 110 // CHECK-NEXT: <key>kind</key><string>control</string> 111 // CHECK-NEXT: <key>edges</key> 112 // CHECK-NEXT: <array> 113 // CHECK-NEXT: <dict> 114 // CHECK-NEXT: <key>start</key> 115 // CHECK-NEXT: <array> 116 // CHECK-NEXT: <dict> 117 // CHECK-NEXT: <key>line</key><integer>24</integer> 118 // CHECK-NEXT: <key>col</key><integer>3</integer> 119 // CHECK-NEXT: <key>file</key><integer>0</integer> 120 // CHECK-NEXT: </dict> 121 // CHECK-NEXT: <dict> 122 // CHECK-NEXT: <key>line</key><integer>24</integer> 123 // CHECK-NEXT: <key>col</key><integer>5</integer> 124 // CHECK-NEXT: <key>file</key><integer>0</integer> 125 // CHECK-NEXT: </dict> 126 // CHECK-NEXT: </array> 127 // CHECK-NEXT: <key>end</key> 128 // CHECK-NEXT: <array> 129 // CHECK-NEXT: <dict> 130 // CHECK-NEXT: <key>line</key><integer>25</integer> 131 // CHECK-NEXT: <key>col</key><integer>3</integer> 132 // CHECK-NEXT: <key>file</key><integer>0</integer> 133 // CHECK-NEXT: </dict> 134 // CHECK-NEXT: <dict> 135 // CHECK-NEXT: <key>line</key><integer>25</integer> 136 // CHECK-NEXT: <key>col</key><integer>4</integer> 137 // CHECK-NEXT: <key>file</key><integer>0</integer> 138 // CHECK-NEXT: </dict> 139 // CHECK-NEXT: </array> 140 // CHECK-NEXT: </dict> 141 // CHECK-NEXT: </array> 142 // CHECK-NEXT: </dict> 143 // CHECK-NEXT: <dict> 144 // CHECK-NEXT: <key>kind</key><string>control</string> 145 // CHECK-NEXT: <key>edges</key> 146 // CHECK-NEXT: <array> 147 // CHECK-NEXT: <dict> 148 // CHECK-NEXT: <key>start</key> 149 // CHECK-NEXT: <array> 150 // CHECK-NEXT: <dict> 151 // CHECK-NEXT: <key>line</key><integer>25</integer> 152 // CHECK-NEXT: <key>col</key><integer>3</integer> 153 // CHECK-NEXT: <key>file</key><integer>0</integer> 154 // CHECK-NEXT: </dict> 155 // CHECK-NEXT: <dict> 156 // CHECK-NEXT: <key>line</key><integer>25</integer> 157 // CHECK-NEXT: <key>col</key><integer>4</integer> 158 // CHECK-NEXT: <key>file</key><integer>0</integer> 159 // CHECK-NEXT: </dict> 160 // CHECK-NEXT: </array> 161 // CHECK-NEXT: <key>end</key> 162 // CHECK-NEXT: <array> 163 // CHECK-NEXT: <dict> 164 // CHECK-NEXT: <key>line</key><integer>31</integer> 165 // CHECK-NEXT: <key>col</key><integer>3</integer> 166 // CHECK-NEXT: <key>file</key><integer>0</integer> 167 // CHECK-NEXT: </dict> 168 // CHECK-NEXT: <dict> 169 // CHECK-NEXT: <key>line</key><integer>31</integer> 170 // CHECK-NEXT: <key>col</key><integer>4</integer> 171 // CHECK-NEXT: <key>file</key><integer>0</integer> 172 // CHECK-NEXT: </dict> 173 // CHECK-NEXT: </array> 174 // CHECK-NEXT: </dict> 175 // CHECK-NEXT: </array> 176 // CHECK-NEXT: </dict> 177 // CHECK-NEXT: <dict> 178 // CHECK-NEXT: <key>kind</key><string>control</string> 179 // CHECK-NEXT: <key>edges</key> 180 // CHECK-NEXT: <array> 181 // CHECK-NEXT: <dict> 182 // CHECK-NEXT: <key>start</key> 183 // CHECK-NEXT: <array> 184 // CHECK-NEXT: <dict> 185 // CHECK-NEXT: <key>line</key><integer>31</integer> 186 // CHECK-NEXT: <key>col</key><integer>3</integer> 187 // CHECK-NEXT: <key>file</key><integer>0</integer> 188 // CHECK-NEXT: </dict> 189 // CHECK-NEXT: <dict> 190 // CHECK-NEXT: <key>line</key><integer>31</integer> 191 // CHECK-NEXT: <key>col</key><integer>4</integer> 192 // CHECK-NEXT: <key>file</key><integer>0</integer> 193 // CHECK-NEXT: </dict> 194 // CHECK-NEXT: </array> 195 // CHECK-NEXT: <key>end</key> 196 // CHECK-NEXT: <array> 197 // CHECK-NEXT: <dict> 198 // CHECK-NEXT: <key>line</key><integer>31</integer> 199 // CHECK-NEXT: <key>col</key><integer>7</integer> 200 // CHECK-NEXT: <key>file</key><integer>0</integer> 201 // CHECK-NEXT: </dict> 202 // CHECK-NEXT: <dict> 203 // CHECK-NEXT: <key>line</key><integer>31</integer> 204 // CHECK-NEXT: <key>col</key><integer>24</integer> 205 // CHECK-NEXT: <key>file</key><integer>0</integer> 206 // CHECK-NEXT: </dict> 207 // CHECK-NEXT: </array> 208 // CHECK-NEXT: </dict> 209 // CHECK-NEXT: </array> 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>31</integer> 220 // CHECK-NEXT: <key>col</key><integer>7</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>31</integer> 225 // CHECK-NEXT: <key>col</key><integer>24</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>35</integer> 233 // CHECK-NEXT: <key>col</key><integer>15</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>35</integer> 238 // CHECK-NEXT: <key>col</key><integer>15</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>35</integer> 250 // CHECK-NEXT: <key>col</key><integer>15</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>35</integer> 258 // CHECK-NEXT: <key>col</key><integer>13</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>35</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>Division by zero</string> 271 // CHECK-NEXT: <key>message</key> 272 // CHECK-NEXT: <string>Division by zero</string> 273 // CHECK-NEXT: </dict> 274 // CHECK-NEXT: </array> 275 // CHECK-NEXT: <key>description</key><string>Division by zero</string> 276 // CHECK-NEXT: <key>category</key><string>Logic error</string> 277 // CHECK-NEXT: <key>type</key><string>Division by zero</string> 278 // CHECK-NEXT: <key>check_name</key><string>core.DivideZero</string> 279 // CHECK-NEXT: <!-- This hash is experimental and going to change! --> 280 // CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>86cb845e4f1e6abde1c5b319d5b08eca</string> 281 // CHECK-NEXT: <key>issue_context_kind</key><string>function</string> 282 // CHECK-NEXT: <key>issue_context</key><string>main</string> 283 // CHECK-NEXT: <key>issue_hash_function_offset</key><string>15</string> 284 // CHECK-NEXT: <key>location</key> 285 // CHECK-NEXT: <dict> 286 // CHECK-NEXT: <key>line</key><integer>35</integer> 287 // CHECK-NEXT: <key>col</key><integer>15</integer> 288 // CHECK-NEXT: <key>file</key><integer>0</integer> 289 // CHECK-NEXT: </dict> 290 // CHECK-NEXT: </dict> 291 // CHECK-NEXT: </array> 292