Skip to content

Add an option -Xllvm -sil-print-on-error. #7189

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
merged 1 commit into from
Feb 1, 2017
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
2 changes: 2 additions & 0 deletions include/swift/SIL/PrettyStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class PrettyStackTraceSILFunction : public llvm::PrettyStackTraceEntry {
PrettyStackTraceSILFunction(const char *action, SILFunction *F)
: TheFn(F), Action(action) {}
virtual void print(llvm::raw_ostream &OS) const;
protected:
void printFunctionInfo(llvm::raw_ostream &out) const;
};

} // end namespace swift
Expand Down
7 changes: 4 additions & 3 deletions include/swift/SILOptimizer/PassManager/PrettyStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_SILOPTIMIZER_PASSMANAGER_PRETTYSTACKTRACE_H
#define SWIFT_SILOPTIMIZER_PASSMANAGER_PRETTYSTACKTRACE_H

#include "swift/SIL/PrettyStackTrace.h"
#include "llvm/Support/PrettyStackTrace.h"

namespace swift {
Expand All @@ -21,14 +22,14 @@ class SILFunctionTransform;
class SILModuleTransform;

class PrettyStackTraceSILFunctionTransform
: public llvm::PrettyStackTraceEntry {
: public PrettyStackTraceSILFunction {
SILFunctionTransform *SFT;
unsigned PassNumber;

public:
PrettyStackTraceSILFunctionTransform(SILFunctionTransform *SFT,
unsigned PassNumber)
: SFT(SFT), PassNumber(PassNumber) {}
unsigned PassNumber);

virtual void print(llvm::raw_ostream &OS) const;
};

Expand Down
12 changes: 12 additions & 0 deletions lib/SIL/PrettyStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

using namespace swift;

llvm::cl::opt<bool>
SILPrintOnError("sil-print-on-error", llvm::cl::init(false),
llvm::cl::desc("Printing SIL function bodies in crash diagnostics."));

void swift::printSILLocationDescription(llvm::raw_ostream &out,
SILLocation loc,
ASTContext &Context) {
Expand Down Expand Up @@ -52,11 +56,19 @@ void PrettyStackTraceSILFunction::print(llvm::raw_ostream &out) const {
return;
}

printFunctionInfo(out);
}

void PrettyStackTraceSILFunction::printFunctionInfo(llvm::raw_ostream &out) const {
out << "\"";
TheFn->printName(out);
out << "\".\n";

if (!TheFn->getLocation().isNull()) {
out << " for ";
printSILLocationDescription(out, TheFn->getLocation(),
TheFn->getModule().getASTContext());
}
if (SILPrintOnError)
TheFn->print(out);
}
10 changes: 7 additions & 3 deletions lib/SILOptimizer/PassManager/PrettyStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

using namespace swift;

PrettyStackTraceSILFunctionTransform::PrettyStackTraceSILFunctionTransform(
SILFunctionTransform *SFT, unsigned PassNumber):
PrettyStackTraceSILFunction("Running SIL Function Transform",
SFT->getFunction()),
SFT(SFT), PassNumber(PassNumber) {}

void PrettyStackTraceSILFunctionTransform::print(llvm::raw_ostream &out) const {
out << "While running pass #" << PassNumber
<< " SILFunctionTransform \"" << SFT->getName()
Expand All @@ -25,9 +31,7 @@ void PrettyStackTraceSILFunctionTransform::print(llvm::raw_ostream &out) const {
out << " <<null>>";
return;
}
out << "\"";
SFT->getFunction()->printName(out);
out << "\".\n";
printFunctionInfo(out);
}

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