Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -Wno-unused-value -emit-llvm < %s -o %t |
| 2 | // RUN: grep volatile %t | count 145 |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 3 | // RUN: grep memcpy %t | count 4 |
| 4 | |
| 5 | volatile int i, j, k; |
| 6 | volatile int ar[5]; |
| 7 | volatile char c; |
| 8 | volatile _Complex int ci; |
| 9 | volatile struct S { |
| 10 | #ifdef __cplusplus |
| 11 | void operator =(volatile struct S&o) volatile; |
| 12 | #endif |
| 13 | int i; |
| 14 | } a, b; |
| 15 | |
| 16 | //void operator =(volatile struct S&o1, volatile struct S&o2) volatile; |
Daniel Dunbar | 23afaad | 2009-11-17 08:57:36 +0000 | [diff] [blame] | 17 | int printf(const char *, ...); |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 18 | |
| 19 | int main() { |
| 20 | // A use. |
| 21 | i; |
| 22 | // A use of the real part |
| 23 | (float)(ci); |
| 24 | // A use. |
| 25 | (void)ci; |
| 26 | // A use. |
| 27 | (void)a; |
| 28 | // Not a use. |
| 29 | (void)(ci=ci); |
| 30 | // Not a use. |
| 31 | (void)(i=j); |
| 32 | ci+=ci; |
| 33 | (ci += ci) + ci; |
| 34 | asm("nop"); |
| 35 | (i += j) + k; |
| 36 | asm("nop"); |
| 37 | // A use |
| 38 | (i += j) + 1; |
| 39 | asm("nop"); |
| 40 | ci+ci; |
| 41 | // A use. |
| 42 | __real i; |
| 43 | // A use. |
| 44 | +ci; |
| 45 | asm("nop"); |
| 46 | // Not a use. |
| 47 | (void)(i=i); |
| 48 | (float)(i=i); |
| 49 | // A use. |
| 50 | (void)i; |
| 51 | i=i; |
| 52 | i=i=i; |
| 53 | #ifndef __cplusplus |
| 54 | // Not a use. |
| 55 | (void)__builtin_choose_expr(0, i=i, j=j); |
| 56 | #endif |
| 57 | // A use. |
| 58 | k ? (i=i) : (j=j); |
| 59 | (void)(i,(i=i)); |
| 60 | i=i,i; |
| 61 | (i=j,k=j); |
| 62 | (i=j,k); |
| 63 | (i,j); |
| 64 | i=c=k; |
| 65 | i+=k; |
| 66 | // A use of both. |
| 67 | ci; |
| 68 | #ifndef __cplusplus |
| 69 | // A use of _real. |
| 70 | (int)ci; |
| 71 | // A use of both. |
| 72 | (_Bool)ci; |
| 73 | #endif |
| 74 | ci=ci; |
| 75 | ci=ci=ci; |
| 76 | __imag ci = __imag ci = __imag ci; |
| 77 | // Not a use. |
| 78 | __real (i = j); |
| 79 | // Not a use. |
| 80 | __imag i; |
| 81 | |
| 82 | // ============================================================ |
Mike Stump | 46cd81f | 2009-05-29 16:24:13 +0000 | [diff] [blame] | 83 | // FIXME: Test cases we get wrong. |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 84 | |
Mike Stump | 2d3b36e | 2009-05-29 16:12:36 +0000 | [diff] [blame] | 85 | // A use. We load all of a into a copy of a, then load i. gcc forgets to do |
| 86 | // the assignment. |
Mike Stump | 46cd81f | 2009-05-29 16:24:13 +0000 | [diff] [blame] | 87 | // (a = a).i; |
Mike Stump | 2d3b36e | 2009-05-29 16:12:36 +0000 | [diff] [blame] | 88 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 89 | // ============================================================ |
| 90 | // Test cases where we intentionally differ from gcc, due to suspected bugs in |
| 91 | // gcc. |
| 92 | |
| 93 | // Not a use. gcc forgets to do the assignment. |
| 94 | ((a=a),a); |
| 95 | |
| 96 | // Not a use. gcc gets this wrong, it doesn't emit the copy! |
| 97 | // (void)(a=a); |
| 98 | |
| 99 | // Not a use. gcc got this wrong in 4.2 and omitted the side effects |
| 100 | // entirely, but it is fixed in 4.4.0. |
| 101 | __imag (i = j); |
| 102 | |
| 103 | #ifndef __cplusplus |
| 104 | // A use of the real part |
| 105 | (float)(ci=ci); |
| 106 | // Not a use, bug? gcc treats this as not a use, that's probably a bug due to |
| 107 | // tree folding ignoring volatile. |
| 108 | (int)(ci=ci); |
| 109 | #endif |
| 110 | |
| 111 | // A use. |
| 112 | (float)(i=i); |
| 113 | // A use. gcc treats this as not a use, that's probably a bug due to tree |
| 114 | // folding ignoring volatile. |
| 115 | (int)(i=i); |
| 116 | |
| 117 | // A use. |
| 118 | -(i=j); |
| 119 | // A use. gcc treats this a not a use, that's probably a bug due to tree |
| 120 | // folding ignoring volatile. |
| 121 | +(i=k); |
| 122 | |
| 123 | // A use. gcc treats this a not a use, that's probably a bug due to tree |
| 124 | // folding ignoring volatile. |
| 125 | __real (ci=ci); |
| 126 | |
| 127 | // A use. |
| 128 | i + 0; |
| 129 | // A use. |
| 130 | (i=j) + i; |
| 131 | // A use. gcc treats this as not a use, that's probably a bug due to tree |
| 132 | // folding ignoring volatile. |
| 133 | (i=j) + 0; |
| 134 | |
| 135 | #ifdef __cplusplus |
| 136 | (i,j)=k; |
| 137 | (j=k,i)=i; |
| 138 | struct { int x; } s, s1; |
| 139 | printf("s is at %p\n", &s); |
| 140 | printf("s is at %p\n", &(s = s1)); |
| 141 | printf("s.x is at %p\n", &((s = s1).x)); |
| 142 | #endif |
| 143 | } |