зеркало из https://github.com/microsoft/clang.git
Use LLVM's new error handler API to report back end errors using Diagnostic.
For example, -- ddunbar@giles:Frontend$ clang -c backend-errors.c fatal error: error in backend: Global variable 'a' has an invalid section specifier 'I AM, not, legal': mach-o section specifier uses an unknown section type. -- compare to: -- ddunbar@giles:Frontend$ gcc -c backend-errors.c /var/folders/DQ/DQ8GT3++HESEzT1obWBynE+++TI/-Tmp-//cc45w2pq.s:2:Expected comma after segment-name /var/folders/DQ/DQ8GT3++HESEzT1obWBynE+++TI/-Tmp-//cc45w2pq.s:2:Rest of line ignored. 1st junk character valued 77 (M). -- Yay! I am not tied to my wording choice, we could also go with "uncoverable error" for the prefix, or just leave it off entirely. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78554 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
1df5109f47
Коммит
70121ebd65
|
@ -13,6 +13,7 @@ def err_fe_unknown_triple : Error<
|
||||||
"unknown target triple '%0', please use -triple or -arch">;
|
"unknown target triple '%0', please use -triple or -arch">;
|
||||||
def err_fe_error_reading : Error<"error reading '%0'">;
|
def err_fe_error_reading : Error<"error reading '%0'">;
|
||||||
def err_fe_error_reading_stdin : Error<"error reading stdin">;
|
def err_fe_error_reading_stdin : Error<"error reading stdin">;
|
||||||
|
def err_fe_error_backend : Error<"error in backend: %0">, DefaultFatal;
|
||||||
|
|
||||||
def note_fixit_applied : Note<"FIX-IT applied suggested code changes">;
|
def note_fixit_applied : Note<"FIX-IT applied suggested code changes">;
|
||||||
def note_fixit_in_macro : Note<
|
def note_fixit_in_macro : Note<
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/PluginLoader.h"
|
#include "llvm/Support/PluginLoader.h"
|
||||||
|
@ -2130,6 +2131,15 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
||||||
static llvm::cl::list<std::string>
|
static llvm::cl::list<std::string>
|
||||||
InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
|
InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
|
||||||
|
|
||||||
|
static void LLVMErrorHandler(void *UserData, const std::string &Message) {
|
||||||
|
Diagnostic &Diags = *static_cast<Diagnostic*>(UserData);
|
||||||
|
|
||||||
|
Diags.Report(FullSourceLoc(), diag::err_fe_error_backend) << Message;
|
||||||
|
|
||||||
|
// We cannot recover from llvm errors.
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
llvm::sys::PrintStackTraceOnErrorSignal();
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
||||||
llvm::PrettyStackTraceProgram X(argc, argv);
|
llvm::PrettyStackTraceProgram X(argc, argv);
|
||||||
|
@ -2208,6 +2218,11 @@ int main(int argc, char **argv) {
|
||||||
OptNoWarnings))
|
OptNoWarnings))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// Set an error handler, so that any LLVM backend diagnostics go through our
|
||||||
|
// error handler.
|
||||||
|
llvm::llvm_install_error_handler(LLVMErrorHandler,
|
||||||
|
static_cast<void*>(&Diags));
|
||||||
|
|
||||||
// -I- is a deprecated GCC feature, scan for it and reject it.
|
// -I- is a deprecated GCC feature, scan for it and reject it.
|
||||||
for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
|
||||||
if (I_dirs[i] == "-") {
|
if (I_dirs[i] == "-") {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче