Clang Project

clang_source_code/test/CodeGenCXX/reference-init.cpp
1// RUN: %clang_cc1 -triple %itanium_abi_triple -verify %s
2// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o - -std=c++98 | FileCheck %s --check-prefix=CHECK-CXX98
3// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o - -std=c++11 | FileCheck %s --check-prefix=CHECK-CXX11
4// expected-no-diagnostics
5
6#if __cplusplus >= 201103L
7// CHECK-CXX11: @_ZZ15InitRefWithListvE1r = internal constant i32* @_ZGRZ15InitRefWithListvE1r_
8// CHECK-CXX11: @_ZGRZ15InitRefWithListvE1r_ = internal constant i32 123
9int InitRefWithList() { static const int &r = {123}; return r; }
10#endif
11
12struct XPTParamDescriptor {};
13struct nsXPTParamInfo {
14  nsXPTParamInfo(const XPTParamDescriptor& desc);
15};
16void a(XPTParamDescriptor *params) {
17  const nsXPTParamInfo& paramInfo = params[0];
18}
19
20// CodeGen of reference initialized const arrays.
21namespace PR5911 {
22  template <typename T, int N> int f(const T (&a)[N]) { return N; }
23  int iarr[] = { 1 };
24  int test() { return f(iarr); }
25}
26
27// radar 7574896
28struct Foo { int foo; };
29Foo& ignoreSetMutex = *(new Foo);
30
31// Binding to a bit-field that requires a temporary. 
32struct { int bitfield : 3; } s = { 3 };
33const int &s2 = s.bitfield;
34
35// In C++98, this forms a reference to itself. In C++11 onwards, this performs
36// copy-construction.
37struct SelfReference { SelfReference &r; };
38extern SelfReference self_reference_1;
39SelfReference self_reference_2 = {self_reference_1};
40// CHECK-CXX98: @self_reference_2 = {{.*}}global %[[SELF_REF:.*]] { %[[SELF_REF]]* @self_reference_1 }
41// CHECK-CXX11: @self_reference_2 = {{(dso_local )?}}global %[[SELF_REF:.*]] zeroinitializer
42// CHECK-CXX11: call {{.*}}memcpy{{.*}} @self_reference_2 {{.*}} @self_reference_1
43