From f2cf329ccd1bf43d7464dab760e907775e414cab Mon Sep 17 00:00:00 2001
From: Daniel Dunbar <daniel@zuster.org>
Date: Tue, 17 Aug 2010 22:32:48 +0000
Subject: [PATCH] Lex: Add #pragma clang __debug {llvm_fatal_error,
 llvm_unreachable}, for testing those crash paths.

llvm-svn: 111311
---
 .../include/clang/Basic/DiagnosticLexKinds.td |  3 +++
 clang/lib/Lex/Pragma.cpp                      | 20 ++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 5068a055e869..08ba1c43ccf9 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -268,6 +268,9 @@ def warn_pragma_diagnostic_invalid_token :
 def warn_pragma_diagnostic_unknown_warning :
    ExtWarn<"unknown warning group '%0', ignored">,
    InGroup<UnknownPragmas>;
+// - #pragma __debug
+def warn_pragma_debug_unexpected_command : Warning<
+  "unexpected debug command '%0'">;
 
 def err_pragma_comment_unknown_kind : Error<"unknown kind of pragma comment">;
 def err_defined_macro_name : Error<"'defined' cannot be used as a macro name">;
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index eec1d1d6eea5..0ef87b96d3ba 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -20,6 +20,7 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <algorithm>
 using namespace clang;
 
@@ -697,20 +698,25 @@ struct PragmaDebugHandler : public PragmaHandler {
     }
     IdentifierInfo *II = Tok.getIdentifierInfo();
 
-    if (II->isStr("overflow_stack")) {
-      DebugOverflowStack();
+    if (II->isStr("assert")) {
+      assert(0 && "This is an assertion!");
     } else if (II->isStr("crash")) {
-      DebugCrash();
+      *(volatile int*) 0x11 = 0;
+    } else if (II->isStr("llvm_fatal_error")) {
+      llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
+    } else if (II->isStr("llvm_unreachable")) {
+      llvm_unreachable("#pragma clang __debug llvm_unreachable");
+    } else if (II->isStr("overflow_stack")) {
+      DebugOverflowStack();
+    } else {
+      PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
+        << II->getName();
     }
   }
 
   void DebugOverflowStack() {
     DebugOverflowStack();
   }
-
-  void DebugCrash() {
-    *(volatile int*) 0x11 = 0;
-  }
 };
 
 /// PragmaDiagnosticHandler - e.g. '#pragma GCC diagnostic ignored "-Wformat"'