diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-01-11 19:59:01 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-01-11 15:48:32 -0500 |
| commit | 95619ecb8ccf8a5405b901e02cfbb389a8f95aba (patch) | |
| tree | 46dce328a8b95b3aaac1fe1e3ed02820f2689533 /src/zig_clang.cpp | |
| parent | 9cc7fb66bc00d54d8e4ff77cb6a0327488ceb59d (diff) | |
| download | zig-95619ecb8ccf8a5405b901e02cfbb389a8f95aba.tar.gz zig-95619ecb8ccf8a5405b901e02cfbb389a8f95aba.zip | |
Stop dropping errors from clang
* Refactor the error-writing code to be more compact and flexible
Diffstat (limited to 'src/zig_clang.cpp')
| -rw-r--r-- | src/zig_clang.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp index dd003a4f9c..0afa2d28ae 100644 --- a/src/zig_clang.cpp +++ b/src/zig_clang.cpp @@ -2111,28 +2111,40 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char llvm::StringRef msg_str_ref = it->getMessage(); Stage2ErrorMsg *msg = errors.add_one(); + memset(msg, 0, sizeof(*msg)); + msg->msg_ptr = (const char *)msg_str_ref.bytes_begin(); msg->msg_len = msg_str_ref.size(); clang::FullSourceLoc fsl = it->getLocation(); + // Expand the location if possible + fsl = fsl.getFileLoc(); + + // The only known way to obtain a Loc without a manager associated + // to it is if you have a lot of errors clang emits "too many errors + // emitted, stopping now" if (fsl.hasManager()) { - clang::FileID file_id = fsl.getFileID(); - clang::StringRef filename = fsl.getManager().getFilename(fsl); - if (filename.empty()) { - msg->filename_ptr = nullptr; - } else { + const clang::SourceManager &SM = fsl.getManager(); + + clang::PresumedLoc presumed_loc = SM.getPresumedLoc(fsl); + assert(!presumed_loc.isInvalid()); + + msg->line = presumed_loc.getLine() - 1; + msg->column = presumed_loc.getColumn() - 1; + + clang::StringRef filename = presumed_loc.getFilename(); + if (!filename.empty()) { msg->filename_ptr = (const char *)filename.bytes_begin(); msg->filename_len = filename.size(); } - msg->source = (const char *)fsl.getManager().getBufferData(file_id).bytes_begin(); - msg->line = fsl.getSpellingLineNumber() - 1; - msg->column = fsl.getSpellingColumnNumber() - 1; - msg->offset = fsl.getManager().getFileOffset(fsl); - } else { - // The only known way this gets triggered right now is if you have a lot of errors - // clang emits "too many errors emitted, stopping now" - msg->filename_ptr = nullptr; - msg->source = nullptr; + + bool invalid; + clang::StringRef buffer = fsl.getBufferData(&invalid); + + if (!invalid) { + msg->source = (const char *)buffer.bytes_begin(); + msg->offset = SM.getFileOffset(fsl); + } } } |
