| 1 |
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++11 -Wuninitialized -verify %s |
| 2 |
|
| 3 |
// test1: Expect no diagnostics |
| 4 |
int test1(int x) { |
| 5 |
int y; |
| 6 |
asm goto("" : "=r"(y) : "r"(x) : : err); |
| 7 |
return y; |
| 8 |
err: |
| 9 |
return -1; |
| 10 |
} |
| 11 |
|
| 12 |
// test2: Expect no diagnostics |
| 13 |
int test2(int x) { |
| 14 |
int y; |
| 15 |
if (x < 42) |
| 16 |
asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2); |
| 17 |
else |
| 18 |
asm goto("" : "+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; |
| 24 |
} |
| 25 |
|
| 26 |
// test3: Expect no diagnostics |
| 27 |
int test3(int x) { |
| 28 |
int y; |
| 29 |
asm goto("" : "=&r"(y) : "r"(x) : : fail); |
| 30 |
normal: |
| 31 |
y += x; |
| 32 |
return y; |
| 33 |
if (x) { |
| 34 |
fail: |
| 35 |
return y; |
| 36 |
} |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
// test4: Expect no diagnostics |
| 41 |
int test4(int x) { |
| 42 |
int y; |
| 43 |
goto forward; |
| 44 |
backward: |
| 45 |
return y; |
| 46 |
forward: |
| 47 |
asm goto("" : "=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 goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect, fallthrough); |
| 55 |
fallthrough: |
| 56 |
return y; |
| 57 |
indirect: |
| 58 |
return -2; |
| 59 |
} |
| 60 |
|
| 61 |
// test6: Expect no diagnostics. |
| 62 |
int test6(unsigned int *x) { |
| 63 |
unsigned int val; |
| 64 |
|
| 65 |
// See through casts and unary operators. |
| 66 |
asm goto("" : "=r" (*(unsigned int *)(&val)) ::: indirect); |
| 67 |
*x = val; |
| 68 |
return 0; |
| 69 |
indirect: |
| 70 |
return -1; |
| 71 |
} |
| 72 |
|
| 73 |
// test7: Expect no diagnostics. |
| 74 |
int test7(int z) { |
| 75 |
int x; |
| 76 |
if (z) |
| 77 |
asm goto ("":"=r"(x):::A1,A2); |
| 78 |
return 0; |
| 79 |
A1: |
| 80 |
A2: |
| 81 |
return x; |
| 82 |
} |
| 83 |
|
| 84 |
// test8: Expect no diagnostics |
| 85 |
int test8() { |
| 86 |
int x = 0; |
| 87 |
asm goto ("":"=r"(x):::A1,A2); |
| 88 |
return 0; |
| 89 |
A1: |
| 90 |
A2: |
| 91 |
return x; |
| 92 |
} |
| 93 |
|
| 94 |
// test9: Expect no diagnostics |
| 95 |
int test9 (int x) { |
| 96 |
int y; |
| 97 |
asm goto("": "=r"(y) :::out); |
| 98 |
return 42; |
| 99 |
out: |
| 100 |
return y; |
| 101 |
} |
| 102 |
|
| 103 |
int test10() { |
| 104 |
int y; // expected-note {{initialize the variable 'y' to silence this warning}} |
| 105 |
asm goto(""::::out); |
| 106 |
return 42; |
| 107 |
out: |
| 108 |
return y; // expected-warning {{variable 'y' is uninitialized when used here}} |
| 109 |
} |