r177919 - Try harder to be signal-safe inside our signal handler. The most prominent behavioural

Nick Lewycky nicholas at mxc.ca
Mon Mar 25 14:24:30 PDT 2013


Author: nicholas
Date: Mon Mar 25 16:24:30 2013
New Revision: 177919

URL: http://llvm.org/viewvc/llvm-project?rev=177919&view=rev
Log:
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.

Added:
    cfe/trunk/test/Parser/crash-report.c
Modified:
    cfe/trunk/lib/Parse/ParseAST.cpp

Modified: cfe/trunk/lib/Parse/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=177919&r1=177918&r2=177919&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseAST.cpp (original)
+++ cfe/trunk/lib/Parse/ParseAST.cpp Mon Mar 25 16:24:30 2013
@@ -55,10 +55,21 @@ void PrettyStackTraceParserEntry::print(
 
   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

Added: cfe/trunk/test/Parser/crash-report.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/crash-report.c?rev=177919&view=auto
==============================================================================
--- cfe/trunk/test/Parser/crash-report.c (added)
+++ cfe/trunk/test/Parser/crash-report.c Mon Mar 25 16:24:30 2013
@@ -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
+





More information about the cfe-commits mailing list