1355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -Wunused-label %s
2e1fcf29951432de60e9fba243d500d069e929900Ted Kremenek// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
3e1fcf29951432de60e9fba243d500d069e929900Ted Kremenek// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
40faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
50faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCallint i = 0;
60faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCallint j = 0;
70faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
80faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCallvoid foo();
90faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
100faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall// PR4806
110faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCallvoid pr4806() {
120faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  1,foo();          // expected-warning {{expression result unused}}
130faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
140faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  // other
150faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo();
160faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i;                // expected-warning {{expression result unused}}
170faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
180faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i,foo();          // expected-warning {{expression result unused}}
190faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),i;          // expected-warning {{expression result unused}}
200faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
2125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  i,j,foo();        // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
2225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  i,foo(),j;        // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
2325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  foo(),i,j;        // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
240faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
250faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++;
260faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
270faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++,foo();
280faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),i++;
290faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
300faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++,j,foo();      // expected-warning {{expression result unused}}
310faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++,foo(),j;      // expected-warning {{expression result unused}}
320faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),i++,j;      // expected-warning {{expression result unused}}
330faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
340faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i,j++,foo();      // expected-warning {{expression result unused}}
350faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i,foo(),j++;      // expected-warning {{expression result unused}}
360faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),i,j++;      // expected-warning {{expression result unused}}
370faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
380faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++,j++,foo();
390faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  i++,foo(),j++;
400faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),i++,j++;
410faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
420faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  {};
430faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  ({});
440faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  ({}),foo();
450faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  foo(),({});
460faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
470faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  (int)1U;          // expected-warning {{expression result unused}}
480faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  (void)1U;
490faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall
500faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  // pointer to volatile has side effect (thus no warning)
510faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  int* pi = &i;
520faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  volatile int* pj = &j;
530faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  *pi;              // expected-warning {{expression result unused}}
540faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall  *pj;
55d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis
56355a9fe26a6dec89680ddf713dd5bc7a671b298aArgyrios Kyrtzidis  foo_label:        // expected-warning {{unused label}}
57d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis  i;                // expected-warning {{expression result unused}}
580faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall}
59c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek
60c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek// Don't warn about unused '||', '&&' expressions that contain assignments.
61c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenekint test_logical_foo1();
62c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenekint test_logical_foo2();
63c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenekint test_logical_foo3();
64c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenekint test_logical_bar() {
65c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek  int x = 0;
66c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek  (x = test_logical_foo1()) ||  // no-warning
67c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek  (x = test_logical_foo2()) ||  // no-warning
68c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek  (x = test_logical_foo3());    // no-warning
6925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis
7025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  x || test_logical_foo1();     // no-warning
7125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis
72c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek  return x;
73c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek}
74c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek
75fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek// PR8282
76fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenekvoid conditional_for_control_flow(int cond, int x, int y)
77fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek{
78fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek    cond? y++ : x; // no-warning
79fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek    cond? y : ++x; // no-warning
80fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek    cond? (x |= y) : ++x; // no-warning
81fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek    cond? y : x; // expected-warning {{expression result unused}}
82fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek}
83fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek
8425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidisstruct s0 { int f0; };
8525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis
8625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidisvoid f0(int a);
8725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidisvoid f1(struct s0 *a) {
8825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  // rdar://8139785
8925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis  f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}}
9025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis}
91