diff options
author | John McCall <rjmccall@apple.com> | 2010-11-16 10:08:07 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-11-16 10:08:07 +0000 |
commit | b418d74c11498b7e1044103131e2e3be4d63512e (patch) | |
tree | 36330e02a9b184864d87e3dff7fcbe0ffe68961d /test/CodeGen/volatile-1.c | |
parent | ac21a21a49131544777f3bd56d2351a4072954ca (diff) | |
download | clang-b418d74c11498b7e1044103131e2e3be4d63512e.tar.gz |
Simplify some complex emission and implement correct semantics for
assignment to volatiles in C. This in effect reverts some of mjs's
work in and around r72572. Basically, the C++ standard is quite
clear, except that it lies about volatile behavior approximating
C's, whereas the C standard is almost actively misleading.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119344 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/volatile-1.c')
-rw-r--r-- | test/CodeGen/volatile-1.c | 204 |
1 files changed, 182 insertions, 22 deletions
diff --git a/test/CodeGen/volatile-1.c b/test/CodeGen/volatile-1.c index e0c672b41e..e4c6c679bd 100644 --- a/test/CodeGen/volatile-1.c +++ b/test/CodeGen/volatile-1.c @@ -1,10 +1,10 @@ -// RUN: %clang_cc1 -Wno-unused-value -emit-llvm < %s -o %t -// RUN: grep volatile %t | count 145 -// RUN: grep memcpy %t | count 4 +// RUN: %clang_cc1 -Wno-unused-value -emit-llvm %s -o - | FileCheck %s +// CHECK: @i = common global [[INT:i[0-9]+]] 0 volatile int i, j, k; volatile int ar[5]; volatile char c; +// CHECK: @ci = common global [[CINT:%.*]] zeroinitializer volatile _Complex int ci; volatile struct S { #ifdef __cplusplus @@ -16,67 +16,190 @@ volatile struct S { //void operator =(volatile struct S&o1, volatile struct S&o2) volatile; int printf(const char *, ...); -int main() { - // A use. + +// Note that these test results are very much specific to C! +// Assignments in C++ yield l-values, not r-values, and the situations +// that do implicit lvalue-to-rvalue conversion are substantially +// reduced. + +// CHECK: define void @test() +void test() { + // CHECK: volatile load [[INT]]* @i i; - // A use of the real part + // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: sitofp [[INT]] (float)(ci); - // A use. + // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) (void)ci; - // A use. + // CHECK-NEXT: bitcast + // CHECK-NEXT: memcpy (void)a; - // Not a use. + // CHECK-NEXT: [[R:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) (void)(ci=ci); - // Not a use. + // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* @j + // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* @i (void)(i=j); + // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // Not sure why they're ordered this way. + // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] + // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] + // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) ci+=ci; + + // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] + // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] + // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // These additions can be elided + // CHECK-NEXT: add [[INT]] [[R]], [[R2]] + // CHECK-NEXT: add [[INT]] [[I]], [[I2]] (ci += ci) + ci; + // CHECK-NEXT: call void asm asm("nop"); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: add nsw [[INT]] + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile load + // CHECK-NEXT: add nsw [[INT]] (i += j) + k; + // CHECK-NEXT: call void asm asm("nop"); - // A use + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: add nsw [[INT]] + // CHECK-NEXT: volatile store + // CHECK-NEXT: add nsw [[INT]] (i += j) + 1; + // CHECK-NEXT: call void asm asm("nop"); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: add [[INT]] + // CHECK-NEXT: add [[INT]] ci+ci; - // A use. + + // CHECK-NEXT: volatile load __real i; - // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load +ci; + // CHECK-NEXT: call void asm asm("nop"); - // Not a use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store (void)(i=i); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: sitofp (float)(i=i); - // A use. + // CHECK-NEXT: volatile load (void)i; + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store i=i; + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store i=i=i; #ifndef __cplusplus - // Not a use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store (void)__builtin_choose_expr(0, i=i, j=j); #endif - // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: icmp + // CHECK-NEXT: br i1 + // CHECK: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: br label + // CHECK: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: br label k ? (i=i) : (j=j); + // CHECK: phi + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store (void)(i,(i=i)); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile load i=i,i; + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store (i=j,k=j); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile load (i=j,k); + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load (i,j); + // CHECK-NEXT: volatile load + // CHECK-NEXT: trunc + // CHECK-NEXT: volatile store + // CHECK-NEXT: sext + // CHECK-NEXT: volatile store i=c=k; + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: add nsw [[INT]] + // CHECK-NEXT: volatile store i+=k; - // A use of both. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load ci; #ifndef __cplusplus - // A use of _real. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load (int)ci; - // A use of both. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: icmp ne + // CHECK-NEXT: icmp ne + // CHECK-NEXT: or i1 (_Bool)ci; #endif + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store ci=ci; + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store ci=ci=ci; + // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) __imag ci = __imag ci = __imag ci; - // Not a use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store __real (i = j); - // Not a use. + // CHECK-NEXT: volatile load __imag i; // ============================================================ @@ -91,6 +214,9 @@ int main() { // gcc. // Not a use. gcc forgets to do the assignment. + // CHECK-NEXT: call void @llvm.memcpy{{.*}}, i1 true + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @llvm.memcpy{{.*}}, i1 true ((a=a),a); // Not a use. gcc gets this wrong, it doesn't emit the copy! @@ -98,38 +224,72 @@ int main() { // Not a use. gcc got this wrong in 4.2 and omitted the side effects // entirely, but it is fixed in 4.4.0. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store __imag (i = j); #ifndef __cplusplus // A use of the real part + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store + // CHECK-NEXT: sitofp (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. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store (int)(ci=ci); #endif // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: sitofp (float)(i=i); // A use. gcc treats this as not a use, that's probably a bug due to tree // folding ignoring volatile. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store (int)(i=i); // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: sub -(i=j); // A use. gcc treats this a not a use, that's probably a bug due to tree // folding ignoring volatile. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store +(i=k); // A use. gcc treats this a not a use, that's probably a bug due to tree // folding ignoring volatile. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile store __real (ci=ci); // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: add i + 0; // A use. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: volatile load + // CHECK-NEXT: add (i=j) + i; // A use. gcc treats this as not a use, that's probably a bug due to tree // folding ignoring volatile. + // CHECK-NEXT: volatile load + // CHECK-NEXT: volatile store + // CHECK-NEXT: add (i=j) + 0; #ifdef __cplusplus |