Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down
17 changes: 16 additions & 1 deletion test/IRGen/globals.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()