[PATCH] D57951: [Lex] Allow to set missing include error to not fatal
Ivan Donchevskii via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 8 06:47:52 PST 2019
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, nik.
For IDE it's a nice feature to not get a fatal error and continue preprocessing even if the file is missing.
This allows include further files and get more relevant information about the current translation unit.
https://reviews.llvm.org/D57951
Files:
include/clang/Basic/Diagnostic.h
include/clang/Basic/DiagnosticLexKinds.td
include/clang/Lex/PreprocessorOptions.h
lib/Frontend/ASTUnit.cpp
lib/Lex/PPDirectives.cpp
lib/Lex/Pragma.cpp
Index: lib/Lex/Pragma.cpp
===================================================================
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -29,6 +29,7 @@
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Lex/PreprocessorLexer.h"
#include "clang/Lex/Token.h"
#include "clang/Lex/TokenLexer.h"
@@ -508,8 +509,12 @@
LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
nullptr, CurDir, nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
- if (!SuppressIncludeNotFoundError)
- Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
+ if (!SuppressIncludeNotFoundError) {
+ Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude
+ ? diag::err_pp_file_not_found_keep_going
+ : diag::err_pp_file_not_found)
+ << Filename;
+ }
return;
}
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1866,8 +1866,10 @@
// If the file is still not found, just go with the vanilla diagnostic
if (!File) {
- Diag(FilenameTok, diag::err_pp_file_not_found) << OriginalFilename
- << FilenameRange;
+ Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude
+ ? diag::err_pp_file_not_found_keep_going
+ : diag::err_pp_file_not_found)
+ << OriginalFilename << FilenameRange;
if (IsFrameworkFound) {
size_t SlashPos = OriginalFilename.find('/');
assert(SlashPos != StringRef::npos &&
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1735,6 +1735,7 @@
PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
PPOpts.SingleFileParseMode = SingleFileParse;
+ PPOpts.KeepGoingAfterMissingInclude = !Diags->getSuppressAfterFatalError();
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
Index: include/clang/Lex/PreprocessorOptions.h
===================================================================
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -142,6 +142,12 @@
/// compiler invocation and its buffers will be reused.
bool RetainRemappedFileBuffers = false;
+ /// Whether to emit normal error instead of fatal in case the include is
+ /// missing. This should help to provide more meaningful information for the
+ /// code that uses data from the following headers which are ignored
+ /// otherwise.
+ bool KeepGoingAfterMissingInclude = false;
+
/// The Objective-C++ ARC standard library that we should support,
/// by providing appropriate definitions to retrofit the standard library
/// with support for lifetime-qualified pointers.
Index: include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -399,6 +399,7 @@
def err_pp_directive_required : Error<
"%0 must be used within a preprocessing directive">;
def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
+def err_pp_file_not_found_keep_going : Error<"'%0' file not found">;
def err_pp_through_header_not_found : Error<
"'%0' required for precompiled header not found">, DefaultFatal;
def err_pp_through_header_not_seen : Error<
Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -618,6 +618,8 @@
/// a fatal error.
void setSuppressAfterFatalError(bool Val) { SuppressAfterFatalError = Val; }
+ bool getSuppressAfterFatalError() { return SuppressAfterFatalError; }
+
/// When set to true mask warnings that come from system headers.
void setSuppressSystemWarnings(bool Val) {
GetCurDiagState()->SuppressSystemWarnings = Val;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57951.185965.patch
Type: text/x-patch
Size: 4368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190208/33d630a9/attachment-0001.bin>
More information about the cfe-commits
mailing list