Richard Smith | 41ae328 | 2012-11-14 00:50:40 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -std=c++11 |FileCheck %s |
Eli Friedman | 01cad4c | 2009-11-07 00:02:45 +0000 | [diff] [blame] | 2 | |
| 3 | class x { |
John McCall | 3155f57 | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 4 | public: int operator=(int); |
Eli Friedman | 01cad4c | 2009-11-07 00:02:45 +0000 | [diff] [blame] | 5 | }; |
| 6 | void a() { |
| 7 | x a; |
| 8 | a = 1u; |
| 9 | } |
Douglas Gregor | 914af21 | 2010-04-23 04:16:32 +0000 | [diff] [blame] | 10 | |
| 11 | void f(int i, int j) { |
| 12 | // CHECK: load i32 |
| 13 | // CHECK: load i32 |
| 14 | // CHECK: add nsw i32 |
| 15 | // CHECK: store i32 |
| 16 | // CHECK: store i32 17, i32 |
| 17 | // CHECK: ret |
| 18 | (i += j) = 17; |
| 19 | } |
John McCall | 9a43e12 | 2011-10-28 01:04:34 +0000 | [diff] [blame] | 20 | |
| 21 | // Taken from g++.old-deja/g++.jason/net.C |
| 22 | namespace test1 { |
| 23 | template <class T> void fn (T t) { } |
| 24 | template <class T> struct A { |
| 25 | void (*p)(T); |
| 26 | A() { p = fn; } |
| 27 | }; |
| 28 | |
| 29 | A<int> a; |
| 30 | } |
Richard Smith | 41ae328 | 2012-11-14 00:50:40 +0000 | [diff] [blame^] | 31 | |
| 32 | // Ensure that we use memcpy when we would have selected a trivial assignment |
| 33 | // operator, even for a non-trivially-copyable type. |
| 34 | struct A { |
| 35 | A &operator=(const A&); |
| 36 | }; |
| 37 | struct B { |
| 38 | B(const B&); |
| 39 | B &operator=(const B&) = default; |
| 40 | int n; |
| 41 | }; |
| 42 | struct C { |
| 43 | A a; |
| 44 | B b[16]; |
| 45 | }; |
| 46 | void b(C &a, C &b) { |
| 47 | // CHECK: define {{.*}} @_ZN1CaSERKS_( |
| 48 | // CHECK: call {{.*}} @_ZN1AaSERKS_( |
| 49 | // CHECK-NOT: call {{.*}} @_ZN1BaSERKS_( |
| 50 | // CHECK: call {{.*}} @{{.*}}memcpy |
| 51 | // CHECK-NOT: call {{.*}} @_ZN1BaSERKS_( |
| 52 | // CHECK: } |
| 53 | a = b; |
| 54 | } |