Skip to content

Commit 83fcb32

Browse files
authored
Merge pull request #7189 from atrick/master
2 parents bbb0912 + a6ebb4e commit 83fcb32

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

include/swift/SIL/PrettyStackTrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class PrettyStackTraceSILFunction : public llvm::PrettyStackTraceEntry {
5050
PrettyStackTraceSILFunction(const char *action, SILFunction *F)
5151
: TheFn(F), Action(action) {}
5252
virtual void print(llvm::raw_ostream &OS) const;
53+
protected:
54+
void printFunctionInfo(llvm::raw_ostream &out) const;
5355
};
5456

5557
} // end namespace swift

include/swift/SILOptimizer/PassManager/PrettyStackTrace.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SILOPTIMIZER_PASSMANAGER_PRETTYSTACKTRACE_H
1414
#define SWIFT_SILOPTIMIZER_PASSMANAGER_PRETTYSTACKTRACE_H
1515

16+
#include "swift/SIL/PrettyStackTrace.h"
1617
#include "llvm/Support/PrettyStackTrace.h"
1718

1819
namespace swift {
@@ -21,14 +22,14 @@ class SILFunctionTransform;
2122
class SILModuleTransform;
2223

2324
class PrettyStackTraceSILFunctionTransform
24-
: public llvm::PrettyStackTraceEntry {
25+
: public PrettyStackTraceSILFunction {
2526
SILFunctionTransform *SFT;
2627
unsigned PassNumber;
2728

2829
public:
2930
PrettyStackTraceSILFunctionTransform(SILFunctionTransform *SFT,
30-
unsigned PassNumber)
31-
: SFT(SFT), PassNumber(PassNumber) {}
31+
unsigned PassNumber);
32+
3233
virtual void print(llvm::raw_ostream &OS) const;
3334
};
3435

lib/SIL/PrettyStackTrace.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
using namespace swift;
2424

25+
llvm::cl::opt<bool>
26+
SILPrintOnError("sil-print-on-error", llvm::cl::init(false),
27+
llvm::cl::desc("Printing SIL function bodies in crash diagnostics."));
28+
2529
void swift::printSILLocationDescription(llvm::raw_ostream &out,
2630
SILLocation loc,
2731
ASTContext &Context) {
@@ -52,11 +56,19 @@ void PrettyStackTraceSILFunction::print(llvm::raw_ostream &out) const {
5256
return;
5357
}
5458

59+
printFunctionInfo(out);
60+
}
61+
62+
void PrettyStackTraceSILFunction::printFunctionInfo(llvm::raw_ostream &out) const {
63+
out << "\"";
5564
TheFn->printName(out);
65+
out << "\".\n";
5666

5767
if (!TheFn->getLocation().isNull()) {
5868
out << " for ";
5969
printSILLocationDescription(out, TheFn->getLocation(),
6070
TheFn->getModule().getASTContext());
6171
}
72+
if (SILPrintOnError)
73+
TheFn->print(out);
6274
}

lib/SILOptimizer/PassManager/PrettyStackTrace.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
using namespace swift;
1919

20+
PrettyStackTraceSILFunctionTransform::PrettyStackTraceSILFunctionTransform(
21+
SILFunctionTransform *SFT, unsigned PassNumber):
22+
PrettyStackTraceSILFunction("Running SIL Function Transform",
23+
SFT->getFunction()),
24+
SFT(SFT), PassNumber(PassNumber) {}
25+
2026
void PrettyStackTraceSILFunctionTransform::print(llvm::raw_ostream &out) const {
2127
out << "While running pass #" << PassNumber
2228
<< " SILFunctionTransform \"" << SFT->getName()
@@ -25,9 +31,7 @@ void PrettyStackTraceSILFunctionTransform::print(llvm::raw_ostream &out) const {
2531
out << " <<null>>";
2632
return;
2733
}
28-
out << "\"";
29-
SFT->getFunction()->printName(out);
30-
out << "\".\n";
34+
printFunctionInfo(out);
3135
}
3236

3337
void PrettyStackTraceSILModuleTransform::print(llvm::raw_ostream &out) const {

0 commit comments

Comments
 (0)