summaryrefslogtreecommitdiffstats
path: root/test/CodeGen/volatile-1.c
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-05-29 15:46:01 +0000
committerMike Stump <mrs@apple.com>2009-05-29 15:46:01 +0000
commit7f79f9be5916c51c35da4f126b7c12596a101607 (patch)
treee9ea6a963a08300641f1485e694233c561340fea /test/CodeGen/volatile-1.c
parent6a7330c20cabf1cf1cd46f5dfc183ec3a72add66 (diff)
Fixup the rest of the trivial cases of the codegen of volatile. If
any body can spot codegen bugs with volatile, or knows of any in the bug database, let me know. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72572 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/volatile-1.c')
-rw-r--r--test/CodeGen/volatile-1.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/test/CodeGen/volatile-1.c b/test/CodeGen/volatile-1.c
new file mode 100644
index 0000000000..ea478841c4
--- /dev/null
+++ b/test/CodeGen/volatile-1.c
@@ -0,0 +1,139 @@
+// RUN: clang-cc -Wno-unused-value -emit-llvm < %s -o %t &&
+// RUN: grep volatile %t | count 145 &&
+// RUN: grep memcpy %t | count 4
+
+volatile int i, j, k;
+volatile int ar[5];
+volatile char c;
+volatile _Complex int ci;
+volatile struct S {
+#ifdef __cplusplus
+ void operator =(volatile struct S&o) volatile;
+#endif
+ int i;
+} a, b;
+
+//void operator =(volatile struct S&o1, volatile struct S&o2) volatile;
+#include <stdio.h>
+
+int main() {
+ // A use.
+ i;
+ // A use of the real part
+ (float)(ci);
+ // A use.
+ (void)ci;
+ // A use.
+ (void)a;
+ // Not a use.
+ (void)(ci=ci);
+ // Not a use.
+ (void)(i=j);
+ ci+=ci;
+ (ci += ci) + ci;
+ asm("nop");
+ (i += j) + k;
+ asm("nop");
+ // A use
+ (i += j) + 1;
+ asm("nop");
+ ci+ci;
+ // A use.
+ __real i;
+ // A use.
+ +ci;
+ asm("nop");
+ // Not a use.
+ (void)(i=i);
+ (float)(i=i);
+ // A use.
+ (void)i;
+ i=i;
+ i=i=i;
+#ifndef __cplusplus
+ // Not a use.
+ (void)__builtin_choose_expr(0, i=i, j=j);
+#endif
+ // A use.
+ k ? (i=i) : (j=j);
+ (void)(i,(i=i));
+ i=i,i;
+ (i=j,k=j);
+ (i=j,k);
+ (i,j);
+ i=c=k;
+ i+=k;
+ // A use of both.
+ ci;
+#ifndef __cplusplus
+ // A use of _real.
+ (int)ci;
+ // A use of both.
+ (_Bool)ci;
+#endif
+ ci=ci;
+ ci=ci=ci;
+ __imag ci = __imag ci = __imag ci;
+ // Not a use.
+ __real (i = j);
+ // Not a use.
+ __imag i;
+
+ // ============================================================
+ // Test cases we get wrong.
+
+ // ============================================================
+ // Test cases where we intentionally differ from gcc, due to suspected bugs in
+ // gcc.
+
+ // Not a use. gcc forgets to do the assignment.
+ ((a=a),a);
+
+ // Not a use. gcc gets this wrong, it doesn't emit the copy!
+ // (void)(a=a);
+
+ // Not a use. gcc got this wrong in 4.2 and omitted the side effects
+ // entirely, but it is fixed in 4.4.0.
+ __imag (i = j);
+
+#ifndef __cplusplus
+ // A use of the real part
+ (float)(ci=ci);
+ // Not a use, bug? gcc treats this as not a use, that's probably a bug due to
+ // tree folding ignoring volatile.
+ (int)(ci=ci);
+#endif
+
+ // A use.
+ (float)(i=i);
+ // A use. gcc treats this as not a use, that's probably a bug due to tree
+ // folding ignoring volatile.
+ (int)(i=i);
+
+ // A use.
+ -(i=j);
+ // A use. gcc treats this a not a use, that's probably a bug due to tree
+ // folding ignoring volatile.
+ +(i=k);
+
+ // A use. gcc treats this a not a use, that's probably a bug due to tree
+ // folding ignoring volatile.
+ __real (ci=ci);
+
+ // A use.
+ i + 0;
+ // A use.
+ (i=j) + i;
+ // A use. gcc treats this as not a use, that's probably a bug due to tree
+ // folding ignoring volatile.
+ (i=j) + 0;
+
+#ifdef __cplusplus
+ (i,j)=k;
+ (j=k,i)=i;
+ struct { int x; } s, s1;
+ printf("s is at %p\n", &s);
+ printf("s is at %p\n", &(s = s1));
+ printf("s.x is at %p\n", &((s = s1).x));
+#endif
+}