diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 4b1ffb0b71ea0..dad6ac28e28e0 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -2942,10 +2942,9 @@ void IRGenSILFunction::visitAllocGlobalInst(AllocGlobalInst *i) { void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { SILGlobalVariable *var = i->getReferencedGlobal(); - SILType loweredTy = var->getLoweredTypeInContext(getExpansionContext()); - assert(loweredTy == i->getType().getObjectType()); + SILType loweredTy = var->getLoweredType(); auto &ti = getTypeInfo(loweredTy); - + auto expansion = IGM.getResilienceExpansionForLayout(var); // If the variable is empty in all resilience domains that can see it, @@ -2968,7 +2967,15 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { // Otherwise, the static storage for the global consists of a fixed-size // buffer; project it. addr = emitProjectValueInBuffer(*this, loweredTy, addr); - + + + // Get the address of the type in context. + SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext()); + auto &tiInContext = getTypeInfo(loweredTyInContext); + auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(), + tiInContext.getStorageType()->getPointerTo()); + addr = Address(ptr, tiInContext.getStorageType(), + tiInContext.getBestKnownAlignment()); setLoweredAddress(i, addr); } diff --git a/test/IRGen/globals.swift b/test/IRGen/globals.swift index dce8d83ad2208..4c84f3270eec9 100644 --- a/test/IRGen/globals.swift +++ b/test/IRGen/globals.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s +// RUN: %target-swift-frontend -primary-file %s -disable-availability-checking -emit-ir | %FileCheck %s // REQUIRES: swift_in_compiler // REQUIRES: PTRSIZE=64 @@ -54,3 +54,18 @@ extension A { // CHECK: define{{( dllexport)?}}{{( protected)?}} i32 @main(i32 %0, i8** %1) {{.*}} { // CHECK: store i64 {{.*}}, i64* getelementptr inbounds ([[INT]], [[INT]]* @"$s7globals2g0Sivp", i32 0, i32 0), align 8 +// CHECK: [[BUF_PROJ:%.*]] = call {{.*}} @__swift_project_value_buffer({{.*}}s7globals1gQrvp +// CHECK: [[CAST:%.*]] = bitcast {{.*}} [[BUF_PROJ]] +// CHECK: [[CAST2:%.*]] = bitcast {{.*}} [[CAST]] +// CHECK: call void @llvm.memcpy{{.*}}({{.*}}[[CAST2]] + + +public protocol Some {} + +public struct Implementer : Some { + var w = (0, 1, 2, 3, 4) + + public init() { } +} + +let g : some Some = Implementer()