Skip to content

IRGen: Add another lldb resilience hack [4.2] #17726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
16 changes: 14 additions & 2 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class alignas(1 << DeclAlignInBits) Decl {
StorageKind : 4
);

SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1,
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1+1,
/// \brief Whether this property is a type property (currently unfortunately
/// called 'static').
IsStatic : 1,
Expand All @@ -347,7 +347,11 @@ class alignas(1 << DeclAlignInBits) Decl {

/// \brief Whether this is a property used in expressions in the debugger.
/// It is up to the debugger to instruct SIL how to access this variable.
IsDebuggerVar : 1
IsDebuggerVar : 1,

/// \brief Whether this is a property defined in the debugger's REPL.
/// FIXME: Remove this once LLDB has proper support for resilience.
IsREPLVar : 1
);

SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1 + NumDefaultArgumentKindBits,
Expand Down Expand Up @@ -4576,6 +4580,7 @@ class VarDecl : public AbstractStorageDecl {
Bits.VarDecl.Specifier = static_cast<unsigned>(Sp);
Bits.VarDecl.IsCaptureList = IsCaptureList;
Bits.VarDecl.IsDebuggerVar = false;
Bits.VarDecl.IsREPLVar = false;
Bits.VarDecl.HasNonPatternBindingInit = false;
setType(Ty);
}
Expand Down Expand Up @@ -4762,6 +4767,13 @@ class VarDecl : public AbstractStorageDecl {
void setDebuggerVar(bool IsDebuggerVar) {
Bits.VarDecl.IsDebuggerVar = IsDebuggerVar;
}

/// Is this a special debugger REPL variable?
/// FIXME: Remove this once LLDB has proper support for resilience.
bool isREPLVar() const { return Bits.VarDecl.IsREPLVar; }
void setREPLVar(bool IsREPLVar) {
Bits.VarDecl.IsREPLVar = IsREPLVar;
}

/// Return the Objective-C runtime name for this property.
Identifier getObjCPropertyName() const;
Expand Down
8 changes: 7 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,12 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
bool inFixedBuffer = false;
bool indirectForDebugInfo = false;

// FIXME: Remove this once LLDB has proper support for resilience.
bool isREPLVar = false;
if (auto *decl = var->getDecl())
if (decl->isREPLVar())
isREPLVar = true;

if (var->isInitializedObject()) {
assert(ti.isFixedSize(expansion));
StructLayout *Layout = StaticObjectLayouts[var].get();
Expand All @@ -2142,7 +2148,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
fixedSize = Layout->getSize();
fixedAlignment = Layout->getAlignment();
assert(fixedAlignment >= TargetInfo.HeapObjectAlignment);
} else if (ti.isFixedSize(expansion)) {
} else if (isREPLVar || ti.isFixedSize(expansion)) {
// Allocate static storage.
auto &fixedTI = cast<FixedTypeInfo>(ti);
storageType = fixedTI.getStorageType();
Expand Down
16 changes: 14 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,9 +1857,15 @@ void IRGenSILFunction::visitAllocGlobalInst(AllocGlobalInst *i) {

auto expansion = IGM.getResilienceExpansionForLayout(var);

// FIXME: Remove this once LLDB has proper support for resilience.
bool isREPLVar = false;
if (auto *decl = var->getDecl())
if (decl->isREPLVar())
isREPLVar = true;

// If the global is fixed-size in all resilience domains that can see it,
// we allocated storage for it statically, and there's nothing to do.
if (ti.isFixedSize(expansion))
if (isREPLVar || ti.isFixedSize(expansion))
return;

// Otherwise, the static storage for the global consists of a fixed-size
Expand Down Expand Up @@ -1887,9 +1893,15 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
NotForDefinition);

// FIXME: Remove this once LLDB has proper support for resilience.
bool isREPLVar = false;
if (auto *decl = var->getDecl())
if (decl->isREPLVar())
isREPLVar = true;

// If the global is fixed-size in all resilience domains that can see it,
// we allocated storage for it statically, and there's nothing to do.
if (ti.isFixedSize(expansion)) {
if (isREPLVar || ti.isFixedSize(expansion)) {
setLoweredAddress(i, addr);
return;
}
Expand Down