xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/assign-operator.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -std=c++11 |FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc class x {
4*f4a2713aSLionel Sambuc public: int operator=(int);
5*f4a2713aSLionel Sambuc };
a()6*f4a2713aSLionel Sambuc void a() {
7*f4a2713aSLionel Sambuc   x a;
8*f4a2713aSLionel Sambuc   a = 1u;
9*f4a2713aSLionel Sambuc }
10*f4a2713aSLionel Sambuc 
f(int i,int j)11*f4a2713aSLionel Sambuc void f(int i, int j) {
12*f4a2713aSLionel Sambuc   // CHECK: load i32
13*f4a2713aSLionel Sambuc   // CHECK: load i32
14*f4a2713aSLionel Sambuc   // CHECK: add nsw i32
15*f4a2713aSLionel Sambuc   // CHECK: store i32
16*f4a2713aSLionel Sambuc   // CHECK: store i32 17, i32
17*f4a2713aSLionel Sambuc   // CHECK: ret
18*f4a2713aSLionel Sambuc   (i += j) = 17;
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc // Taken from g++.old-deja/g++.jason/net.C
22*f4a2713aSLionel Sambuc namespace test1 {
fn(T t)23*f4a2713aSLionel Sambuc   template <class T> void fn (T t) { }
24*f4a2713aSLionel Sambuc   template <class T> struct A {
25*f4a2713aSLionel Sambuc     void (*p)(T);
Atest1::A26*f4a2713aSLionel Sambuc     A() { p = fn; }
27*f4a2713aSLionel Sambuc   };
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc   A<int> a;
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc // Ensure that we use memcpy when we would have selected a trivial assignment
33*f4a2713aSLionel Sambuc // operator, even for a non-trivially-copyable type.
34*f4a2713aSLionel Sambuc struct A {
35*f4a2713aSLionel Sambuc   A &operator=(const A&);
36*f4a2713aSLionel Sambuc };
37*f4a2713aSLionel Sambuc struct B {
38*f4a2713aSLionel Sambuc   B(const B&);
39*f4a2713aSLionel Sambuc   B &operator=(const B&) = default;
40*f4a2713aSLionel Sambuc   int n;
41*f4a2713aSLionel Sambuc };
42*f4a2713aSLionel Sambuc struct C {
43*f4a2713aSLionel Sambuc   A a;
44*f4a2713aSLionel Sambuc   B b[16];
45*f4a2713aSLionel Sambuc };
b(C & a,C & b)46*f4a2713aSLionel Sambuc void b(C &a, C &b) {
47*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN1CaSERKS_(
48*f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN1AaSERKS_(
49*f4a2713aSLionel Sambuc   // CHECK-NOT: call {{.*}} @_ZN1BaSERKS_(
50*f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @{{.*}}memcpy
51*f4a2713aSLionel Sambuc   // CHECK-NOT: call {{.*}} @_ZN1BaSERKS_(
52*f4a2713aSLionel Sambuc   // CHECK: }
53*f4a2713aSLionel Sambuc   a = b;
54*f4a2713aSLionel Sambuc }
55