llvm-project/clang/test/Analysis/diagnostics/undef-value-param.c

452 lines
17 KiB
C
Raw Normal View History

// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=text -verify %s
// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=plist-multi-file %s -o - | FileCheck %s
void foo_irrelevant(int c) {
if (c)
return;
c++;
return;
}
void foo(int c, int *x) {
if (c)
//expected-note@-1{{Assuming 'c' is not equal to 0}}
//expected-note@-2{{Taking true branch}}
return;
*x = 5;
}
int use(int c) {
int xx; //expected-note{{Variable 'xx' declared without an initial value}}
int *y = &xx;
foo (c, y);
//expected-note@-1{{Calling 'foo'}}
//expected-note@-2{{Returning from 'foo'}}
foo_irrelevant(c);
return xx+3; //expected-warning{{The left operand of '+' is a garbage value}}
//expected-note@-1{{The left operand of '+' is a garbage value}}
}
//CHECK: <dict>
//CHECK: <key>files</key>
//CHECK: <array>
//CHECK: </array>
//CHECK: <key>diagnostics</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>path</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>19</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>ranges</key>
//CHECK: <array>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>19</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>19</integer>
//CHECK: <key>col</key><integer>10</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Variable &apos;xx&apos; declared without an initial value</string>
//CHECK: <key>message</key>
//CHECK: <string>Variable &apos;xx&apos; declared without an initial value</string>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>19</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>19</integer>
//CHECK: <key>col</key><integer>7</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>7</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>ranges</key>
//CHECK: <array>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>14</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Calling &apos;foo&apos;</string>
//CHECK: <key>message</key>
//CHECK: <string>Calling &apos;foo&apos;</string>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>10</integer>
//CHECK: <key>col</key><integer>1</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Entered call from &apos;use&apos;</string>
//CHECK: <key>message</key>
//CHECK: <string>Entered call from &apos;use&apos;</string>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>10</integer>
//CHECK: <key>col</key><integer>1</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>10</integer>
//CHECK: <key>col</key><integer>4</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>6</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>6</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>ranges</key>
//CHECK: <array>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Assuming &apos;c&apos; is not equal to 0</string>
//CHECK: <key>message</key>
//CHECK: <string>Assuming &apos;c&apos; is not equal to 0</string>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>11</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>14</integer>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>14</integer>
//CHECK: <key>col</key><integer>14</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>ranges</key>
//CHECK: <array>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>14</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Returning from &apos;foo&apos;</string>
//CHECK: <key>message</key>
//CHECK: <string>Returning from &apos;foo&apos;</string>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>21</integer>
//CHECK: <key>col</key><integer>7</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>24</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>24</integer>
//CHECK: <key>col</key><integer>18</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>24</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>24</integer>
//CHECK: <key>col</key><integer>18</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>10</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>control</string>
//CHECK: <key>edges</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>start</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>10</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>end</key>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>12</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>13</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>kind</key><string>event</string>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>12</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <key>ranges</key>
//CHECK: <array>
//CHECK: <array>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>12</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>13</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>The left operand of &apos;+&apos; is a garbage value</string>
//CHECK: <key>message</key>
//CHECK: <string>The left operand of &apos;+&apos; is a garbage value</string>
//CHECK: </dict>
//CHECK: </array>
//CHECK: <key>description</key><string>The left operand of &apos;+&apos; is a garbage value</string>
//CHECK: <key>category</key><string>Logic error</string>
//CHECK: <key>type</key><string>Result of operation is garbage or undefined</string>
//CHECK: <key>issue_context_kind</key><string>function</string>
//CHECK: <key>issue_context</key><string>use</string>
//CHECK: <key>issue_hash</key><integer>7</integer>
//CHECK: <key>location</key>
//CHECK: <dict>
//CHECK: <key>line</key><integer>25</integer>
//CHECK: <key>col</key><integer>12</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
//CHECK: </dict>
//CHECK: </array>
//CHECK: </dict>
//CHECK: </plist>