diff options
-rw-r--r-- | lib/Parse/ParseAST.cpp | 19 | ||||
-rw-r--r-- | test/Parser/crash-report.c | 9 |
2 files changed, 24 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 diff --git a/test/Parser/crash-report.c b/test/Parser/crash-report.c new file mode 100644 index 0000000000..42481aa7d0 --- /dev/null +++ b/test/Parser/crash-report.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s 2>&1 | FileCheck %s +// REQUIRES: crash-recovery + +#prag\ +ma clang __debug crash + +// CHECK: prag\ +// CHECK-NEXT: ma + |