| 1 |
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++98 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s |
| 2 |
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s |
| 3 |
|
| 4 |
// Check that IR gen doesn't try to do an lvalue-to-rvalue conversion |
| 5 |
// on a volatile reference result. |
| 6 |
namespace test0 { |
| 7 |
struct A { |
| 8 |
A(const A& t); |
| 9 |
A& operator=(const A& t); |
| 10 |
volatile A& operator=(const volatile A& t) volatile; |
| 11 |
}; |
| 12 |
|
| 13 |
volatile A *array; |
| 14 |
|
| 15 |
// CHECK-LABEL: define{{.*}} void @_ZN5test04testENS_1AE( |
| 16 |
void test(A t) { |
| 17 |
// CHECK: [[ARR:%.*]] = load ptr, ptr @_ZN5test05arrayE, align 8 |
| 18 |
// CHECK-NEXT: [[IDX:%.*]] = getelementptr inbounds [[A:%.*]], ptr [[ARR]], i64 0 |
| 19 |
// CHECK-NEXT: [[TMP:%.*]] = call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZNV5test01AaSERVKS0_(ptr {{[^,]*}} [[IDX]], ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[T:%.*]]) |
| 20 |
// CHECK-NEXT: ret void |
| 21 |
array[0] = t; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
namespace test1 { |
| 26 |
volatile int *x; |
| 27 |
|
| 28 |
// CHECK-LABEL: define{{.*}} void @_ZN5test14testEv() |
| 29 |
void test() { |
| 30 |
// CHECK: [[TMP:%.*]] = load ptr, ptr @_ZN5test11xE, align 8 |
| 31 |
// CHECK11-NEXT: {{%.*}} = load volatile i32, ptr [[TMP]], align 4 |
| 32 |
// CHECK-NEXT: ret void |
| 33 |
*x; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
namespace PR40642 { |
| 38 |
template <class T> struct S { |
| 39 |
// CHECK-LABEL: define {{.*}} @_ZN7PR406421SIiE3fooEv( |
| 40 |
void foo() { |
| 41 |
// CHECK98-NOT: load volatile |
| 42 |
// CHECK11: load volatile |
| 43 |
if (true) |
| 44 |
reinterpret_cast<const volatile unsigned char *>(m_ptr)[0]; |
| 45 |
// CHECK: } |
| 46 |
} |
| 47 |
int *m_ptr; |
| 48 |
}; |
| 49 |
|
| 50 |
void f(S<int> *x) { x->foo(); } |
| 51 |
} |