aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2013-03-25 21:24:30 +0000
committerNick Lewycky <nicholas@mxc.ca>2013-03-25 21:24:30 +0000
commitcdd81e5a68cefd5ba057f1f638f31a3ec6ace18d (patch)
tree6e8966a8eb8b34cc117f0d98030c5bcf8f20b4ab /lib/Parse
parentd44d2872b2ebe58237de4dbc350b82cab944ccc5 (diff)
Try harder to be signal-safe inside our signal handler. The most prominent behavioural
difference is that we no longer clean the token before emitting it. This fixes a bug where clang hangs in the middle of crashing because the crash handler calls malloc from inside a crash that happened inside of free. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177919 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r--lib/Parse/ParseAST.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp
index 5e769c5691..7cd8a21ac4 100644
--- a/lib/Parse/ParseAST.cpp
+++ b/lib/Parse/ParseAST.cpp
@@ -55,10 +55,21 @@ void PrettyStackTraceParserEntry::print(raw_ostream &OS) const {
const Preprocessor &PP = P.getPreprocessor();
Tok.getLocation().print(OS, PP.getSourceManager());
- if (Tok.isAnnotation())
- OS << ": at annotation token \n";
- else
- OS << ": current parser token '" << PP.getSpelling(Tok) << "'\n";
+ if (Tok.isAnnotation()) {
+ OS << ": at annotation token\n";
+ } else {
+ // Do the equivalent of PP.getSpelling(Tok) except for the parts that would
+ // allocate memory.
+ bool Invalid = false;
+ const SourceManager &SM = P.getPreprocessor().getSourceManager();
+ unsigned Length = Tok.getLength();
+ const char *Spelling = SM.getCharacterData(Tok.getLocation(), &Invalid);
+ if (Invalid) {
+ OS << ": unknown current parser token\n";
+ return;
+ }
+ OS << ": current parser token '" << StringRef(Spelling, Length) << "'\n";
+ }
}
} // namespace