Skip to content

Commit 0120f13

Browse files
committed
[SILVerifier] Log on bad debug-info.
Previously, logging of the actually problematic instruction was guarded by LLVM_DEBUG. Meanwhile the verifier's require method prints an instruction (usually one different from that at which the non-contiguous scope was encountered). Here, instead, the problematic instruction and the instruction which defined the previous scope are printed to llvm::errs always (i.e. whenever verification is actually run). Additionally, debug-info logging is forcibly set on upon failure so that the logs clearly show both what the previous scope was, what the current scope is, and what instructions defined them.
1 parent 6f716a5 commit 0120f13

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static llvm::cl::opt<bool> SkipConvertEscapeToNoescapeAttributes(
7979
// Allow unit tests to gradually migrate toward -allow-critical-edges=false.
8080
static llvm::cl::opt<bool> AllowCriticalEdges("allow-critical-edges",
8181
llvm::cl::init(true));
82+
extern llvm::cl::opt<bool> SILPrintDebugInfo;
8283

8384
// The verifier is basically all assertions, so don't compile it with NDEBUG to
8485
// prevent release builds from triggering spurious unused variable warnings.
@@ -5801,6 +5802,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
58015802
return;
58025803

58035804
const SILDebugScope *LastSeenScope = nullptr;
5805+
SILInstruction *LastSeenScopeInst = nullptr;
58045806
for (SILInstruction &SI : *BB) {
58055807
if (SI.isMetaInstruction())
58065808
continue;
@@ -5814,6 +5816,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
58145816
if (!AlreadySeenScopes.count(DS)) {
58155817
AlreadySeenScopes.insert(DS);
58165818
LastSeenScope = DS;
5819+
LastSeenScopeInst = &SI;
58175820
continue;
58185821
}
58195822

@@ -5838,13 +5841,24 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
58385841

58395842
if (isAncestorScope(DS, LastSeenScope)) {
58405843
LastSeenScope = DS;
5844+
LastSeenScopeInst = &SI;
58415845
continue;
58425846
}
58435847
if (DS != LastSeenScope) {
5844-
LLVM_DEBUG(llvm::dbgs() << "Broken instruction!\n"; SI.dump());
5845-
LLVM_DEBUG(llvm::dbgs() << "Please report a bug on bugs.swift.org\n");
5846-
LLVM_DEBUG(llvm::dbgs() <<
5847-
"Pass -Xllvm -verify-di-holes=false to disable the verification\n");
5848+
llvm::errs() << "Broken instruction!\n";
5849+
SI.dump();
5850+
llvm::errs() << "in scope\n";
5851+
DS->print(SI.getFunction()->getModule());
5852+
llvm::errs() << "Previous, non-contiguous scope set by";
5853+
LastSeenScopeInst->dump();
5854+
llvm::errs() << "in scope\n";
5855+
LastSeenScope->print(SI.getFunction()->getModule());
5856+
llvm::errs() << "Please report a bug on bugs.swift.org\n";
5857+
llvm::errs() <<
5858+
"Pass -Xllvm -verify-di-holes=false to disable the verification\n";
5859+
// Turn on debug info printing so that the log actually shows the bad
5860+
// scopes.
5861+
SILPrintDebugInfo.setValue(true);
58485862
require(
58495863
DS == LastSeenScope,
58505864
"Basic block contains a non-contiguous lexical scope at -Onone");

0 commit comments

Comments
 (0)