Extract key to avoid preemptive mallocs in insert/emplace in associative containers

Summary: This patch applies Duncan's work on __hash_table to __tree.

Reviewers: mclow.lists, dexonsmith

Subscribers: dexonsmith, cfe-commits

Differential Revision: http://reviews.llvm.org/D18637

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@266491 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/support/assert_checkpoint.h b/test/support/assert_checkpoint.h
new file mode 100644
index 0000000..eea78ef
--- /dev/null
+++ b/test/support/assert_checkpoint.h
@@ -0,0 +1,62 @@
+#ifndef SUPPORT_ASSERT_CHECKPOINT_H
+#define SUPPORT_ASSERT_CHECKPOINT_H
+
+#include <csignal>
+#include <iostream>
+#include <cstdlib>
+
+struct Checkpoint {
+  const char* file;
+  const char* func;
+  int line;
+  const char* msg;
+
+  template <class Stream>
+  void print(Stream& s) const {
+      if (!file) {
+          s << "NO CHECKPOINT\n";
+          return;
+      }
+      s << file << ":" << line << " " << func << ": Checkpoint";
+      if (msg)
+        s << " '" << msg << "'";
+      s << std::endl;
+  }
+};
+
+inline Checkpoint& globalCheckpoint() {
+    static Checkpoint C;
+    return C;
+}
+
+inline void clearCheckpoint() {
+    globalCheckpoint() = Checkpoint{0};
+}
+
+#define CHECKPOINT(msg) globalCheckpoint() = Checkpoint{__FILE__, __PRETTY_FUNCTION__, __LINE__, msg}
+
+inline void checkpointSignalHandler(int signal) {
+    if (signal == SIGABRT) {
+        globalCheckpoint().print(std::cerr);
+    } else {
+        std::cerr << "Unexpected signal " << signal << " received\n";
+    }
+    std::_Exit(EXIT_FAILURE);
+}
+
+inline bool initCheckpointHandler() {
+    typedef void(*HandlerT)(int);
+    static bool isInit = false;
+    if (isInit) return true;
+    HandlerT prev_h = std::signal(SIGABRT, checkpointSignalHandler);
+    if (prev_h == SIG_ERR) {
+        std::cerr << "Setup failed.\n";
+        std::_Exit(EXIT_FAILURE);
+    }
+    isInit = true;
+    return false;
+}
+
+static bool initDummy = initCheckpointHandler();
+
+#endif