Bill Wendling | 218dd33 | 2020-03-10 15:26:03 -0700 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++11 -Wuninitialized -verify %s |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 2 | |
Bill Wendling | 72aa619 | 2020-03-10 13:47:30 -0700 | [diff] [blame] | 3 | // test1: Expect no diagnostics |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 4 | int test1(int x) { |
| 5 | int y; |
Bill Wendling | 6d0d1a6 | 2020-02-25 12:31:20 -0800 | [diff] [blame] | 6 | asm goto("nop" : "=r"(y) : "r"(x) : : err); |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 7 | return y; |
| 8 | err: |
| 9 | return -1; |
| 10 | } |
Bill Wendling | 72aa619 | 2020-03-10 13:47:30 -0700 | [diff] [blame] | 11 | |
| 12 | int test2(int x) { |
| 13 | int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} \ |
| 14 | // expected-note {{initialize the variable}} |
| 15 | if (x < 42) |
| 16 | asm volatile goto("testl %0, %0; testl %1, %2; jne %l3" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2); |
| 17 | else |
| 18 | asm volatile goto("testl %0, %1; testl %2, %3; jne %l5" : "+S"(x), "+D"(y) : "r"(x), "r"(y) :: indirect_1, indirect_2); |
| 19 | return x + y; |
| 20 | indirect_1: |
| 21 | return -42; |
| 22 | indirect_2: |
| 23 | return y; // expected-note {{uninitialized use occurs here}} |
| 24 | } |
| 25 | |
| 26 | int test3(int x) { |
| 27 | int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} \ |
| 28 | // expected-note {{initialize the variable}} |
| 29 | asm goto("xorl %1, %0; jmp %l2" : "=&r"(y) : "r"(x) : : fail); |
| 30 | normal: |
| 31 | y += x; |
| 32 | return y; |
| 33 | if (x) { |
| 34 | fail: |
| 35 | return y; // expected-note {{uninitialized use occurs here}} |
| 36 | } |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | int test4(int x) { |
| 41 | int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} \ |
| 42 | // expected-note {{initialize the variable}} |
| 43 | goto forward; |
| 44 | backward: |
| 45 | return y; // expected-note {{uninitialized use occurs here}} |
| 46 | forward: |
| 47 | asm goto("# %0 %1 %2" : "=r"(y) : "r"(x) : : backward); |
| 48 | return y; |
| 49 | } |
| 50 | |
| 51 | // test5: Expect no diagnostics |
| 52 | int test5(int x) { |
| 53 | int y; |
| 54 | asm volatile goto("testl %0, %0; testl %1, %2; jne %l3" : "+S"(x), "+D"(y) : "r"(x) :: indirect, fallthrough); |
| 55 | fallthrough: |
| 56 | return y; |
| 57 | indirect: |
| 58 | return -2; |
| 59 | } |