From: Daniel Dunbar Date: Tue, 17 Aug 2010 22:32:48 +0000 (+0000) Subject: Lex: Add #pragma clang __debug {llvm_fatal_error, llvm_unreachable}, for testing X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5505413ee8e4e2924f52ba81181071f3a492e7d9;p=clang Lex: Add #pragma clang __debug {llvm_fatal_error, llvm_unreachable}, for testing those crash paths. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111311 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 5068a055e8..08ba1c43cc 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/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; +// - #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/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index eec1d1d6ee..0ef87b96d3 100644 --- a/lib/Lex/Pragma.cpp +++ b/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 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"'