Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -2860,14 +2860,19 @@ } // Create a global variable for this lifetime-extended temporary. - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(getModule(), Type, Constant, - llvm::GlobalValue::PrivateLinkage, - InitialValue, Name.c_str()); + unsigned AddrSpace = GetGlobalVarAddressSpace( + VD, getContext().getTargetAddressSpace(MaterializedType)); + llvm::GlobalVariable *GV = new llvm::GlobalVariable( + getModule(), Type, Constant, llvm::GlobalValue::ExternalLinkage, + InitialValue, Name.c_str(), /*InsertBefore=*/nullptr, + llvm::GlobalVariable::NotThreadLocal, AddrSpace); GV->setAlignment( getContext().getTypeAlignInChars(MaterializedType).getQuantity()); if (VD->getTLSKind()) setTLSMode(GV, *VD); + llvm::GlobalValue::LinkageTypes Linkage = + GetLLVMLinkageVarDefinition(VD, Constant); + GV->setLinkage(Linkage); Slot = GV; return GV; } Index: test/CodeGenCXX/const-init-cxx11.cpp =================================================================== --- test/CodeGenCXX/const-init-cxx11.cpp +++ test/CodeGenCXX/const-init-cxx11.cpp @@ -226,30 +226,30 @@ }; // This creates a non-const temporary and binds a reference to it. - // CHECK: @[[TEMP:.*]] = private global {{.*}} { i32 5 }, align 4 + // CHECK: @[[TEMP:.*]] = global {{.*}} { i32 5 }, align 4 // CHECK: @_ZN16LiteralReference3litE = constant {{.*}} @[[TEMP]], align 8 const Lit &lit = Lit(); // This creates a const temporary as part of the reference initialization. - // CHECK: @[[TEMP:.*]] = private constant {{.*}} { i32 5 }, align 4 + // CHECK: @[[TEMP:.*]] = constant {{.*}} { i32 5 }, align 4 // CHECK: @_ZN16LiteralReference4lit2E = constant {{.*}} @[[TEMP]], align 8 const Lit &lit2 = {}; struct A { int &&r1; const int &&r2; }; struct B { A &&a1; const A &&a2; }; B b = { { 0, 1 }, { 2, 3 } }; - // CHECK: @[[TEMP0:.*]] = private global i32 0, align 4 - // CHECK: @[[TEMP1:.*]] = private constant i32 1, align 4 - // CHECK: @[[TEMPA1:.*]] = private global {{.*}} { i32* @[[TEMP0]], i32* @[[TEMP1]] }, align 8 - // CHECK: @[[TEMP2:.*]] = private global i32 2, align 4 - // CHECK: @[[TEMP3:.*]] = private constant i32 3, align 4 - // CHECK: @[[TEMPA2:.*]] = private constant {{.*}} { i32* @[[TEMP2]], i32* @[[TEMP3]] }, align 8 + // CHECK: @[[TEMP0:.*]] = global i32 0, align 4 + // CHECK: @[[TEMP1:.*]] = constant i32 1, align 4 + // CHECK: @[[TEMPA1:.*]] = global {{.*}} { i32* @[[TEMP0]], i32* @[[TEMP1]] }, align 8 + // CHECK: @[[TEMP2:.*]] = global i32 2, align 4 + // CHECK: @[[TEMP3:.*]] = constant i32 3, align 4 + // CHECK: @[[TEMPA2:.*]] = constant {{.*}} { i32* @[[TEMP2]], i32* @[[TEMP3]] }, align 8 // CHECK: @_ZN16LiteralReference1bE = global {{.*}} { {{.*}}* @[[TEMPA1]], {{.*}}* @[[TEMPA2]] }, align 8 struct Subobj { int a, b, c; }; - // CHECK: @[[TEMP:.*]] = private global {{.*}} { i32 1, i32 2, i32 3 }, align 4 + // CHECK: @[[TEMP:.*]] = global {{.*}} { i32 1, i32 2, i32 3 }, align 4 // CHECK: @_ZN16LiteralReference2soE = constant {{.*}} (i8* getelementptr {{.*}} @[[TEMP]]{{.*}}, i64 4) constexpr int &&so = Subobj{ 1, 2, 3 }.b; @@ -258,11 +258,11 @@ constexpr Derived() : Dummy{200}, Subobj{4, 5, 6} {} }; using ConstDerived = const Derived; - // CHECK: @[[TEMPCOMMA:.*]] = private constant {{.*}} { i32 200, i32 4, i32 5, i32 6 } + // CHECK: @[[TEMPCOMMA:.*]] = constant {{.*}} { i32 200, i32 4, i32 5, i32 6 } // CHECK: @_ZN16LiteralReference5commaE = constant {{.*}} getelementptr {{.*}} @[[TEMPCOMMA]]{{.*}}, i64 8) constexpr const int &comma = (1, (2, ConstDerived{}).b); - // CHECK: @[[TEMPDERIVED:.*]] = private global {{.*}} { i32 200, i32 4, i32 5, i32 6 } + // CHECK: @[[TEMPDERIVED:.*]] = global {{.*}} { i32 200, i32 4, i32 5, i32 6 } // CHECK: @_ZN16LiteralReference4baseE = constant {{.*}} getelementptr {{.*}} @[[TEMPDERIVED]]{{.*}}, i64 4) constexpr Subobj &&base = Derived{}; @@ -371,10 +371,10 @@ namespace ArrayTemporary { struct A { const int (&x)[3]; }; struct B { const A (&x)[2]; }; - // CHECK: @[[A1:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 1, i32 2, i32 3] - // CHECK: @[[A2:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 4, i32 5, i32 6] - // CHECK: @[[ARR:_ZGRN14ArrayTemporary1bE.*]] = private constant [2 x {{.*}}] [{{.*}} { [3 x i32]* @[[A1]] }, {{.*}} { [3 x i32]* @[[A2]] }] - // CHECK: @[[B:_ZGRN14ArrayTemporary1bE.*]] = private global {{.*}} { [2 x {{.*}}]* @[[ARR]] } + // CHECK: @[[A1:_ZGRN14ArrayTemporary1bE.*]] = constant [3 x i32] [i32 1, i32 2, i32 3] + // CHECK: @[[A2:_ZGRN14ArrayTemporary1bE.*]] = constant [3 x i32] [i32 4, i32 5, i32 6] + // CHECK: @[[ARR:_ZGRN14ArrayTemporary1bE.*]] = constant [2 x {{.*}}] [{{.*}} { [3 x i32]* @[[A1]] }, {{.*}} { [3 x i32]* @[[A2]] }] + // CHECK: @[[B:_ZGRN14ArrayTemporary1bE.*]] = global {{.*}} { [2 x {{.*}}]* @[[ARR]] } // CHECK: @_ZN14ArrayTemporary1bE = constant {{.*}}* @[[B]] B &&b = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } }; } @@ -382,7 +382,7 @@ namespace UnemittedTemporaryDecl { constexpr int &&ref = 0; extern constexpr int &ref2 = ref; - // CHECK: @_ZGRN22UnemittedTemporaryDecl3refE = private global i32 0 + // CHECK: @_ZGRN22UnemittedTemporaryDecl3refE = global i32 0 // FIXME: This declaration should not be emitted -- it isn't odr-used. // CHECK: @_ZN22UnemittedTemporaryDecl3refE Index: test/CodeGenCXX/const-init-cxx1y.cpp =================================================================== --- test/CodeGenCXX/const-init-cxx1y.cpp +++ test/CodeGenCXX/const-init-cxx1y.cpp @@ -23,18 +23,18 @@ struct A { int &&temporary; int x; }; constexpr int f(int &r) { r *= 9; return r - 12; } A a = { 6, f(a.temporary) }; - // CHECK: @_ZGRN21ModifyStaticTemporary1aE = private global i32 54 + // CHECK: @_ZGRN21ModifyStaticTemporary1aE = global i32 54 // CHECK: @_ZN21ModifyStaticTemporary1aE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1aE, i32 42 A b = { 7, ++b.temporary }; - // CHECK: @_ZGRN21ModifyStaticTemporary1bE = private global i32 8 + // CHECK: @_ZGRN21ModifyStaticTemporary1bE = global i32 8 // CHECK: @_ZN21ModifyStaticTemporary1bE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1bE, i32 8 // Can't emit all of 'c' as a constant here, so emit the initial value of // 'c.temporary', not the value as modified by the partial evaluation within // the initialization of 'c.x'. A c = { 10, (++c.temporary, b.x) }; - // CHECK: @_ZGRN21ModifyStaticTemporary1cE = private global i32 10 + // CHECK: @_ZGRN21ModifyStaticTemporary1cE = global i32 10 // CHECK: @_ZN21ModifyStaticTemporary1cE = global {{.*}} zeroinitializer } Index: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-pr12086.cpp =================================================================== --- test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-pr12086.cpp +++ test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-pr12086.cpp @@ -55,10 +55,10 @@ {1, a}, {3, b}, {5, c} }; -// CHECK-STATIC-BL: @_ZGR6nested = private constant [2 x i32] [i32 1, i32 2], align 4 -// CHECK-STATIC-BL: @_ZGR6nested1 = private constant [2 x i32] [i32 3, i32 4], align 4 -// CHECK-STATIC-BL: @_ZGR6nested2 = private constant [2 x i32] [i32 5, i32 6], align 4 -// CHECK-STATIC-BL: @_ZGR6nested3 = private constant [3 x {{.*}}] [ +// CHECK-STATIC-BL: @_ZGR6nested = constant [2 x i32] [i32 1, i32 2], align 4 +// CHECK-STATIC-BL: @_ZGR6nested1 = constant [2 x i32] [i32 3, i32 4], align 4 +// CHECK-STATIC-BL: @_ZGR6nested2 = constant [2 x i32] [i32 5, i32 6], align 4 +// CHECK-STATIC-BL: @_ZGR6nested3 = constant [3 x {{.*}}] [ // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested, i32 0, i32 0), i64 2 }, // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i32 0, i32 0), i64 2 }, // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested2, i32 0, i32 0), i64 2 } @@ -66,10 +66,10 @@ // CHECK-STATIC-BL: @nested = global {{.*}} { {{.*}} getelementptr inbounds ([3 x {{.*}}]* @_ZGR6nested3, i32 0, i32 0), i64 3 }, align 8 // CHECK-DYNAMIC-BL: @nested = global -// CHECK-DYNAMIC-BL: @_ZGR6nested = private global [3 x -// CHECK-DYNAMIC-BL: @_ZGR6nested1 = private global [2 x i32] zeroinitializer -// CHECK-DYNAMIC-BL: @_ZGR6nested2 = private global [2 x i32] zeroinitializer -// CHECK-DYNAMIC-BL: @_ZGR6nested3 = private global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BL: @_ZGR6nested = global [3 x +// CHECK-DYNAMIC-BL: @_ZGR6nested1 = global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BL: @_ZGR6nested2 = global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BL: @_ZGR6nested3 = global [2 x i32] zeroinitializer // CHECK-DYNAMIC-BL: store i32 1, i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 0) // CHECK-DYNAMIC-BL: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 1) // CHECK-DYNAMIC-BL: store i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 0), @@ -89,10 +89,10 @@ // CHECK-DYNAMIC-BL: {{.*}}** getelementptr inbounds ({{.*}}* @nested, i32 0, i32 0), align 8 // CHECK-DYNAMIC-BL: store i64 3, i64* getelementptr inbounds ({{.*}}* @nested, i32 0, i32 1), align 8 -// CHECK-STATIC-BE: @_ZGR6nested = private constant [2 x i32] [i32 1, i32 2], align 4 -// CHECK-STATIC-BE: @_ZGR6nested1 = private constant [2 x i32] [i32 3, i32 4], align 4 -// CHECK-STATIC-BE: @_ZGR6nested2 = private constant [2 x i32] [i32 5, i32 6], align 4 -// CHECK-STATIC-BE: @_ZGR6nested3 = private constant [3 x {{.*}}] [ +// CHECK-STATIC-BE: @_ZGR6nested = constant [2 x i32] [i32 1, i32 2], align 4 +// CHECK-STATIC-BE: @_ZGR6nested1 = constant [2 x i32] [i32 3, i32 4], align 4 +// CHECK-STATIC-BE: @_ZGR6nested2 = constant [2 x i32] [i32 5, i32 6], align 4 +// CHECK-STATIC-BE: @_ZGR6nested3 = constant [3 x {{.*}}] [ // CHECK-STATIC-BE: {{.*}} { i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested, i32 0, i32 0), // CHECK-STATIC-BE: i32* bitcast (i8* getelementptr (i8* bitcast ([2 x i32]* @_ZGR6nested to i8*), i64 8) to i32*) } // CHECK-STATIC-BE: {{.*}} { i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i32 0, i32 0), @@ -104,10 +104,10 @@ // CHECK-STATIC-BE: {{.*}} bitcast ({{.*}}* getelementptr (i8* bitcast ([3 x {{.*}}]* @_ZGR6nested3 to i8*), i64 48) to {{.*}}*) } // CHECK-DYNAMIC-BE: @nested = global -// CHECK-DYNAMIC-BE: @_ZGR6nested = private global [3 x -// CHECK-DYNAMIC-BE: @_ZGR6nested1 = private global [2 x i32] zeroinitializer -// CHECK-DYNAMIC-BE: @_ZGR6nested2 = private global [2 x i32] zeroinitializer -// CHECK-DYNAMIC-BE: @_ZGR6nested3 = private global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BE: @_ZGR6nested = global [3 x +// CHECK-DYNAMIC-BE: @_ZGR6nested1 = global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BE: @_ZGR6nested2 = global [2 x i32] zeroinitializer +// CHECK-DYNAMIC-BE: @_ZGR6nested3 = global [2 x i32] zeroinitializer // CHECK-DYNAMIC-BE: store i32 1, i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 0) // CHECK-DYNAMIC-BE: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 1) // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32]* @_ZGR6nested1, i64 0, i64 0), Index: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp =================================================================== --- test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp +++ test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp @@ -32,7 +32,7 @@ }; } -// CHECK: @_ZGR15globalInitList1 = private constant [3 x i32] [i32 1, i32 2, i32 3] +// CHECK: @_ZGR15globalInitList1 = constant [3 x i32] [i32 1, i32 2, i32 3] // CHECK: @globalInitList1 = global {{[^ ]+}} { i32* getelementptr inbounds ([3 x i32]* @_ZGR15globalInitList1, {{[^)]*}}), i32* std::initializer_list globalInitList1 = {1, 2, 3}; Index: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp =================================================================== --- test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp +++ test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -47,7 +47,7 @@ ~wantslist1(); }; -// CHECK: @_ZGR15globalInitList1 = private constant [3 x i32] [i32 1, i32 2, i32 3] +// CHECK: @_ZGR15globalInitList1 = constant [3 x i32] [i32 1, i32 2, i32 3] // CHECK: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32]* @_ZGR15globalInitList1, i32 0, i32 0), i{{32|64}} 3 } std::initializer_list globalInitList1 = {1, 2, 3}; @@ -57,20 +57,20 @@ // objects aren't really a problem). // // CHECK: @_ZN25thread_local_global_array1xE = thread_local global - // CHECK: @_ZGRN25thread_local_global_array1xE = private thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4] + // CHECK: @_ZGRN25thread_local_global_array1xE = thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4] std::initializer_list thread_local x = { 1, 2, 3, 4 }; } // CHECK: @globalInitList2 = global %{{[^ ]+}} zeroinitializer -// CHECK: @_ZGR15globalInitList2 = private global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer +// CHECK: @_ZGR15globalInitList2 = global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer // CHECK: @_ZN15partly_constant1kE = global i32 0, align 4 // CHECK: @_ZN15partly_constant2ilE = global {{.*}} null, align 8 -// CHECK: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = private global {{.*}} zeroinitializer, align 8 -// CHECK: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = private global [3 x {{.*}}] zeroinitializer, align 8 -// CHECK: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = private constant [3 x i32] [i32 1, i32 2, i32 3], align 4 -// CHECK: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = private global [2 x i32] zeroinitializer, align 4 -// CHECK: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = private constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4 +// CHECK: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = global {{.*}} zeroinitializer, align 8 +// CHECK: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = global [3 x {{.*}}] zeroinitializer, align 8 +// CHECK: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = constant [3 x i32] [i32 1, i32 2, i32 3], align 4 +// CHECK: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = global [2 x i32] zeroinitializer, align 4 +// CHECK: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4 // CHECK: appending global Index: test/CodeGenCXX/cxx11-thread-local.cpp =================================================================== --- test/CodeGenCXX/cxx11-thread-local.cpp +++ test/CodeGenCXX/cxx11-thread-local.cpp @@ -35,7 +35,7 @@ // CHECK: @_ZZ8tls_dtorvE1u = internal thread_local global // CHECK: @_ZGVZ8tls_dtorvE1u = internal thread_local global i8 0 -// CHECK: @_ZGRZ8tls_dtorvE1u = private thread_local global +// CHECK: @_ZGRZ8tls_dtorvE1u = internal thread_local global // CHECK: @_ZGVN1VIiE1mE = weak_odr thread_local global i64 0 Index: test/CodeGenCXX/temporaries.cpp =================================================================== --- test/CodeGenCXX/temporaries.cpp +++ test/CodeGenCXX/temporaries.cpp @@ -3,7 +3,7 @@ namespace PR16263 { const unsigned int n = 1234; extern const int &r = (const int&)n; - // CHECK: @_ZGRN7PR162631rE = private constant i32 1234, + // CHECK: @_ZGRN7PR162631rE = constant i32 1234, // CHECK: @_ZN7PR162631rE = constant i32* @_ZGRN7PR162631rE, extern const int &s = reinterpret_cast(n); @@ -14,16 +14,16 @@ struct B { int n; }; struct C : A, B {}; extern const A &&a = (A&&)(A&&)(C&&)(C{}); - // CHECK: @_ZGRN7PR162631aE = private global {{.*}} zeroinitializer, + // CHECK: @_ZGRN7PR162631aE = global {{.*}} zeroinitializer, // CHECK: @_ZN7PR162631aE = constant {{.*}} bitcast ({{.*}}* @_ZGRN7PR162631aE to extern const int &&t = ((B&&)C{}).n; - // CHECK: @_ZGRN7PR162631tE = private global {{.*}} zeroinitializer, + // CHECK: @_ZGRN7PR162631tE = global {{.*}} zeroinitializer, // CHECK: @_ZN7PR162631tE = constant i32* {{.*}}* @_ZGRN7PR162631tE {{.*}} 4 struct D { double d; C c; }; extern const int &&u = (123, static_cast(0, ((D&&)D{}).*&D::c).n); - // CHECK: @_ZGRN7PR162631uE = private global {{.*}} zeroinitializer + // CHECK: @_ZGRN7PR162631uE = global {{.*}} zeroinitializer // CHECK: @_ZN7PR162631uE = constant i32* {{.*}} @_ZGRN7PR162631uE {{.*}} 12 }