Skip to content

Commit 0e031d9

Browse files
committed
---
yaml --- r: 347363 b: refs/heads/master c: e2ffa48 h: refs/heads/master i: 347361: 0414514 347359: 4289149
1 parent 5b095ec commit 0e031d9

File tree

8 files changed

+51
-61
lines changed

8 files changed

+51
-61
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d9afc650dc2721f9301cc489d2a1dc009df34525
2+
refs/heads/master: e2ffa482cc419bb7322d6f2a3e30b60467116943
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Remote/FailureKinds.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ FAILURE(TypeHasNoSuchMember,
2727
FAILURE(CouldNotResolveTypeDecl,
2828
"could not resolve a type with mangled name '%0'", (String))
2929

30+
FAILURE(NotFixedLayout,
31+
"query cannot be determined for a type with no fixed layout", ())
32+
3033
#undef FAILURE

trunk/lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ bool LinkInfo::isUsed(IRLinkage IRL) {
16421642
llvm::GlobalVariable *swift::irgen::createVariable(
16431643
IRGenModule &IGM, LinkInfo &linkInfo, llvm::Type *storageType,
16441644
Alignment alignment, DebugTypeInfo DbgTy, Optional<SILLocation> DebugLoc,
1645-
StringRef DebugName, bool inFixedBuffer, bool indirectForDebugInfo) {
1645+
StringRef DebugName, bool inFixedBuffer) {
16461646
auto name = linkInfo.getName();
16471647
llvm::GlobalValue *existingValue = IGM.Module.getNamedGlobal(name);
16481648
if (existingValue) {
@@ -1676,7 +1676,7 @@ llvm::GlobalVariable *swift::irgen::createVariable(
16761676
if (IGM.DebugInfo && !DbgTy.isNull() && linkInfo.isForDefinition())
16771677
IGM.DebugInfo->emitGlobalVariableDeclaration(
16781678
var, DebugName.empty() ? name : DebugName, name, DbgTy,
1679-
var->hasInternalLinkage(), indirectForDebugInfo, DebugLoc);
1679+
var->hasInternalLinkage(), inFixedBuffer, DebugLoc);
16801680

16811681
return var;
16821682
}
@@ -1814,13 +1814,6 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
18141814
Size fixedSize;
18151815
Alignment fixedAlignment;
18161816
bool inFixedBuffer = false;
1817-
bool indirectForDebugInfo = false;
1818-
1819-
// FIXME: Remove this once LLDB has proper support for resilience.
1820-
bool isREPLVar = false;
1821-
if (auto *decl = var->getDecl())
1822-
if (decl->isREPLVar())
1823-
isREPLVar = true;
18241817

18251818
if (var->isInitializedObject()) {
18261819
assert(ti.isFixedSize(expansion));
@@ -1842,7 +1835,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
18421835
fixedAlignment = Layout->getAlignment();
18431836
castStorageToType = cast<FixedTypeInfo>(ti).getStorageType();
18441837
assert(fixedAlignment >= TargetInfo.HeapObjectAlignment);
1845-
} else if (isREPLVar || ti.isFixedSize(expansion)) {
1838+
} else if (ti.isFixedSize(expansion)) {
18461839
// Allocate static storage.
18471840
auto &fixedTI = cast<FixedTypeInfo>(ti);
18481841
storageType = fixedTI.getStorageType();
@@ -1855,28 +1848,6 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
18551848
storageType = getFixedBufferTy();
18561849
fixedSize = Size(DataLayout.getTypeAllocSize(storageType));
18571850
fixedAlignment = Alignment(DataLayout.getABITypeAlignment(storageType));
1858-
1859-
// DebugInfo is not resilient for now, so disable resilience to figure out
1860-
// if lldb needs to dereference the global variable or not.
1861-
//
1862-
// FIXME: Once lldb can make use of remote mirrors to calculate layouts
1863-
// at runtime, this should be removed.
1864-
{
1865-
LoweringModeScope Scope(*this, TypeConverter::Mode::CompletelyFragile);
1866-
1867-
SILType loweredTy = var->getLoweredType();
1868-
auto &nonResilientTI = cast<FixedTypeInfo>(getTypeInfo(loweredTy));
1869-
auto packing = nonResilientTI.getFixedPacking(*this);
1870-
switch (packing) {
1871-
case FixedPacking::OffsetZero:
1872-
break;
1873-
case FixedPacking::Allocate:
1874-
indirectForDebugInfo = true;
1875-
break;
1876-
default:
1877-
llvm_unreachable("Bad packing");
1878-
}
1879-
}
18801851
}
18811852

18821853
// Check whether we've created the global variable already.
@@ -1918,8 +1889,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
19181889
auto DbgTy = DebugTypeInfo::getGlobal(var, storageTypeWithContainer,
19191890
fixedSize, fixedAlignment);
19201891
gvar = createVariable(*this, link, storageTypeWithContainer,
1921-
fixedAlignment, DbgTy, loc, name, inFixedBuffer,
1922-
indirectForDebugInfo);
1892+
fixedAlignment, DbgTy, loc, name, inFixedBuffer);
19231893
}
19241894
/// Add a zero initializer.
19251895
if (forDefinition)

trunk/lib/IRGen/GenDecl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ namespace irgen {
5050
createVariable(IRGenModule &IGM, LinkInfo &linkInfo, llvm::Type *objectType,
5151
Alignment alignment, DebugTypeInfo DebugType = DebugTypeInfo(),
5252
Optional<SILLocation> DebugLoc = None,
53-
StringRef DebugName = StringRef(), bool heapAllocated = false,
54-
bool indirectForDebugInfo = false);
53+
StringRef DebugName = StringRef(), bool heapAllocated = false);
5554

5655
void disableAddressSanitizer(IRGenModule &IGM, llvm::GlobalVariable *var);
5756
}

trunk/lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10661066
llvm::dwarf::DW_LANG_Swift, nullptr, MangledName);
10671067
}
10681068

1069+
llvm::DIType *createFixedValueBufferStruct(llvm::DIType *PointeeTy) {
1070+
unsigned Line = 0;
1071+
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(0);
1072+
llvm::DINode::DIFlags Flags = llvm::DINode::FlagArtificial;
1073+
llvm::DIFile *File = MainFile;
1074+
llvm::DIScope *Scope = TheCU;
1075+
llvm::Metadata *Elements[] = {DBuilder.createMemberType(
1076+
Scope, "contents", File, 0, PtrSize, 0, 0, Flags, PointeeTy)};
1077+
return DBuilder.createStructType(
1078+
Scope, "$swift.fixedbuffer", File, Line, 3 * PtrSize, 0, Flags,
1079+
/* DerivedFrom */ nullptr, DBuilder.getOrCreateArray(Elements),
1080+
llvm::dwarf::DW_LANG_Swift, nullptr);
1081+
}
1082+
10691083
llvm::DIType *createFunctionPointer(DebugTypeInfo DbgTy, llvm::DIScope *Scope,
10701084
unsigned SizeInBits, unsigned AlignInBits,
10711085
llvm::DINode::DIFlags Flags,
@@ -2227,7 +2241,7 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
22272241

22282242
void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
22292243
llvm::GlobalVariable *Var, StringRef Name, StringRef LinkageName,
2230-
DebugTypeInfo DbgTy, bool IsLocalToUnit, bool Indirect,
2244+
DebugTypeInfo DbgTy, bool IsLocalToUnit, bool InFixedBuffer,
22312245
Optional<SILLocation> Loc) {
22322246
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
22332247
return;
@@ -2240,16 +2254,16 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
22402254
// would confuse both the user and LLDB.
22412255
return;
22422256

2257+
if (InFixedBuffer)
2258+
Ty = createFixedValueBufferStruct(Ty);
2259+
22432260
auto L = getStartLocation(Loc);
22442261
auto File = getOrCreateFile(L.Filename);
22452262

22462263
// Emit it as global variable of the current module.
22472264
llvm::DIExpression *Expr = nullptr;
22482265
if (!Var)
22492266
Expr = DBuilder.createConstantValueExpression(0);
2250-
else if (Indirect)
2251-
Expr =
2252-
DBuilder.createExpression(ArrayRef<uint64_t>(llvm::dwarf::DW_OP_deref));
22532267
auto *GV = DBuilder.createGlobalVariableExpression(
22542268
MainModule, Name, LinkageName, File, L.Line, Ty, IsLocalToUnit, Expr);
22552269
if (Var)
@@ -2388,10 +2402,10 @@ void IRGenDebugInfo::emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
23882402

23892403
void IRGenDebugInfo::emitGlobalVariableDeclaration(
23902404
llvm::GlobalVariable *Storage, StringRef Name, StringRef LinkageName,
2391-
DebugTypeInfo DebugType, bool IsLocalToUnit, bool Indirect,
2405+
DebugTypeInfo DebugType, bool IsLocalToUnit, bool InFixedBuffer,
23922406
Optional<SILLocation> Loc) {
23932407
static_cast<IRGenDebugInfoImpl *>(this)->emitGlobalVariableDeclaration(
2394-
Storage, Name, LinkageName, DebugType, IsLocalToUnit, Indirect, Loc);
2408+
Storage, Name, LinkageName, DebugType, IsLocalToUnit, InFixedBuffer, Loc);
23952409
}
23962410

23972411
void IRGenDebugInfo::emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,

trunk/lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,15 +1884,9 @@ void IRGenSILFunction::visitAllocGlobalInst(AllocGlobalInst *i) {
18841884

18851885
auto expansion = IGM.getResilienceExpansionForLayout(var);
18861886

1887-
// FIXME: Remove this once LLDB has proper support for resilience.
1888-
bool isREPLVar = false;
1889-
if (auto *decl = var->getDecl())
1890-
if (decl->isREPLVar())
1891-
isREPLVar = true;
1892-
18931887
// If the global is fixed-size in all resilience domains that can see it,
18941888
// we allocated storage for it statically, and there's nothing to do.
1895-
if (isREPLVar || ti.isFixedSize(expansion))
1889+
if (ti.isFixedSize(expansion))
18961890
return;
18971891

18981892
// Otherwise, the static storage for the global consists of a fixed-size
@@ -1920,15 +1914,9 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
19201914
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
19211915
NotForDefinition);
19221916

1923-
// FIXME: Remove this once LLDB has proper support for resilience.
1924-
bool isREPLVar = false;
1925-
if (auto *decl = var->getDecl())
1926-
if (decl->isREPLVar())
1927-
isREPLVar = true;
1928-
19291917
// If the global is fixed-size in all resilience domains that can see it,
19301918
// we allocated storage for it statically, and there's nothing to do.
1931-
if (isREPLVar || ti.isFixedSize(expansion)) {
1919+
if (ti.isFixedSize(expansion)) {
19321920
setLoweredAddress(i, addr);
19331921
return;
19341922
}

trunk/lib/RemoteAST/RemoteAST.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,21 @@ class RemoteASTContextImpl {
327327
return fail<uint64_t>(Failure::TypeHasNoSuchMember, memberName);
328328

329329
// Fast path: element 0 is always at offset 0.
330-
if (targetIndex == 0) return uint64_t(0);
330+
if (targetIndex == 0)
331+
return uint64_t(0);
331332

332333
// Create an IRGen instance.
333334
auto irgen = getIRGen();
334-
if (!irgen) return Result<uint64_t>::emplaceFailure(Failure::Unknown);
335+
if (!irgen)
336+
return Result<uint64_t>::emplaceFailure(Failure::Unknown);
335337
auto &IGM = irgen->IGM;
336-
337338
SILType loweredTy = IGM.getLoweredType(type);
338339

340+
// Only the runtime metadata knows the offsets of resilient members.
341+
auto &typeInfo = IGM.getTypeInfo(loweredTy);
342+
if (!isa<irgen::FixedTypeInfo>(&typeInfo))
343+
return Result<uint64_t>::emplaceFailure(Failure::NotFixedLayout);
344+
339345
// If the type has a statically fixed offset, return that.
340346
if (auto offset =
341347
irgen::getFixedTupleElementOffset(IGM, loweredTy, targetIndex))

trunk/test/DebugInfo/global_resilience.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ let large = Rectangle(p: Point(x: 1, y: 2), s: Size(w: 3, h: 4), color: 5)
2222
// CHECK-SAME: !dbg ![[LARGE:[0-9]+]]
2323

2424
// CHECK: ![[SMALL]] = !DIGlobalVariableExpression(
25+
// CHECK-SAME: var: ![[VAR_SMALL:[0-9]+]]
2526
// CHECK-SAME: expr: !DIExpression())
27+
// CHECK: ![[VAR_SMALL]] = distinct !DIGlobalVariable(
28+
// CHECK-SAME: type: ![[SMALL_TY:[0-9]+]]
29+
// CHECK: ![[SMALL_TY]] = !DICompositeType(tag: DW_TAG_structure_type,
30+
// CHECK-SAME: name: "$swift.fixedbuffer",
2631
// CHECK: ![[LARGE]] = !DIGlobalVariableExpression(
27-
// CHECK-SAME: expr: !DIExpression(DW_OP_deref))
32+
// CHECK-SAME: var: ![[VAR_LARGE:[0-9]+]]
33+
// CHECK-SAME: expr: !DIExpression())
34+
// CHECK: ![[VAR_LARGE]] = distinct !DIGlobalVariable(
35+
// CHECK-SAME: type: ![[LARGE_TY:[0-9]+]]
36+
// CHECK: ![[LARGE_TY]] = !DICompositeType(tag: DW_TAG_structure_type,
37+
// CHECK-SAME: name: "$swift.fixedbuffer",

0 commit comments

Comments
 (0)