Skip to content

Commit 2207151

Browse files
Merge pull request swiftlang#28008 from adrian-prantl/nodebug
Add a hidden option to disable debugger shadow copies.
2 parents 17169fc + ed82942 commit 2207151

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ class IRGenOptions {
209209
/// Disable round-trip verification of mangled debug types.
210210
unsigned DisableRoundTripDebugTypes : 1;
211211

212+
/// Whether to disable shadow copies for local variables on the stack. This is
213+
/// only used for testing.
214+
unsigned DisableDebuggerShadowCopies : 1;
215+
212216
/// Path to the profdata file to be used for PGO, or the empty string.
213217
std::string UseProfile = "";
214218

@@ -237,8 +241,7 @@ class IRGenOptions {
237241
Sanitizers(OptionSet<SanitizerKind>()),
238242
DebugInfoLevel(IRGenDebugInfoLevel::None),
239243
DebugInfoFormat(IRGenDebugInfoFormat::None),
240-
DisableClangModuleSkeletonCUs(false),
241-
UseJIT(false),
244+
DisableClangModuleSkeletonCUs(false), UseJIT(false),
242245
IntegratedREPL(false), DisableLLVMOptzns(false),
243246
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
244247
DisableFPElim(true), Playground(false), EmitStackPromotionChecks(false),
@@ -250,8 +253,8 @@ class IRGenOptions {
250253
LazyInitializeProtocolConformances(false), DisableLegacyTypeInfo(false),
251254
UseIncrementalLLVMCodeGen(true), UseSwiftCall(false),
252255
GenerateProfile(false), EnableDynamicReplacementChaining(false),
253-
DisableRoundTripDebugTypes(false), CmdArgs(),
254-
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
256+
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),
257+
CmdArgs(), SanitizeCoverage(llvm::SanitizerCoverageOptions()),
255258
TypeInfoFilter(TypeInfoDumpFilter::All) {}
256259

257260
/// Appends to \p os an arbitrary string representing all options which

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ def debugger_testing_transform : Flag<["-"], "debugger-testing-transform">,
453453
HelpText<"Instrument the code with calls to an intrinsic that record the expected values of "
454454
"local variables so they can be compared against the results from the debugger.">;
455455

456+
def disable_debugger_shadow_copies : Flag<["-"], "disable-debugger-shadow-copies">,
457+
HelpText<"Disable debugger shadow copies of local variables."
458+
"This option is only useful for testing the compiler.">,
459+
Flags<[FrontendOption, HelpHidden]>;
460+
456461
def playground : Flag<["-"], "playground">,
457462
HelpText<"Apply the playground semantics and transformation">;
458463

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
10781078
if (Args.hasArg(OPT_no_clang_module_breadcrumbs))
10791079
Opts.DisableClangModuleSkeletonCUs = true;
10801080

1081+
if (Args.hasArg(OPT_disable_debugger_shadow_copies))
1082+
Opts.DisableDebuggerShadowCopies = true;
1083+
10811084
if (Args.hasArg(OPT_use_jit))
10821085
Opts.UseJIT = true;
10831086

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ class IRGenSILFunction :
787787
Alignment Align = Alignment(0)) {
788788
// Never emit shadow copies when optimizing, or if already on the stack.
789789
// No debug info is emitted for refcounts either.
790-
if (IGM.IRGen.Opts.shouldOptimize() || IsAnonymous ||
790+
if (IGM.IRGen.Opts.DisableDebuggerShadowCopies ||
791+
IGM.IRGen.Opts.shouldOptimize() || IsAnonymous ||
791792
isa<llvm::AllocaInst>(Storage) || isa<llvm::UndefValue>(Storage) ||
792793
Storage->getType() == IGM.RefCountedPtrTy)
793794
return Storage;
@@ -830,7 +831,8 @@ class IRGenSILFunction :
830831
Explosion e = getLoweredExplosion(SILVal);
831832

832833
// Only do this at -O0.
833-
if (IGM.IRGen.Opts.shouldOptimize() || IsAnonymous) {
834+
if (IGM.IRGen.Opts.DisableDebuggerShadowCopies ||
835+
IGM.IRGen.Opts.shouldOptimize() || IsAnonymous) {
834836
auto vals = e.claimAll();
835837
copy.append(vals.begin(), vals.end());
836838
return;
@@ -4009,7 +4011,8 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
40094011
isa<llvm::IntrinsicInst>(addr));
40104012

40114013
auto Indirection = DirectValue;
4012-
if (!IGM.IRGen.Opts.shouldOptimize())
4014+
if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&
4015+
!IGM.IRGen.Opts.shouldOptimize())
40134016
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
40144017
if (!Alloca->isStaticAlloca()) {
40154018
// Store the address of the dynamic alloca on the stack.

test/DebugInfo/shadow_copies.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-frontend %s -Onone -emit-ir -g -o - | %FileCheck %s
2-
2+
// RUN: %target-swift-frontend %s -Onone -emit-ir -g -o - \
3+
// RUN: -disable-debugger-shadow-copies | %FileCheck %s --check-prefix=NOCOPY
34
class ClassA
45
{
56
var x : Int64
@@ -16,11 +17,17 @@ class ClassB : ClassA
1617
{
1718
override init (_ input : Int64)
1819
{
19-
// CHECK: @"$s{{.*}}6ClassBCyACs5Int64Vcfc"
20-
// CHECK: alloca {{.*}}ClassBC*
21-
// CHECK: alloca i64
22-
// CHECK-NOT: alloca
23-
// CHECK: ret {{.*}}ClassBC
20+
// CHECK: @"$s{{.*}}6ClassBCyACs5Int64Vcfc"
21+
// NOPCOPY: @"$s{{.*}}6ClassBCyACs5Int64Vcfc"
22+
// CHECK: alloca {{.*}}ClassBC*
23+
// NOPCOPY: alloca {{.*}}ClassBC*
24+
25+
// CHECK: alloca i64
26+
27+
// CHECK-NOT: alloca
28+
// NOPCOPY-NOT: alloca
29+
// CHECK: ret {{.*}}ClassBC
30+
// NOCOPY: ret {{.*}}ClassBC
2431
super.init (input)
2532
}
2633
}

0 commit comments

Comments
 (0)