diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2012-07-17 23:19:16 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2012-07-17 23:19:16 +0000 |
| commit | 8f94ac6922f46afb9dcd97ab30b4c4c3845debd4 (patch) | |
| tree | 4ef4f4e2844c8420332a5bd2d93cb3b793853519 /clang | |
| parent | 4b12ba0ce6684f2b5f3462f70d6c35de162cf31a (diff) | |
| download | bcm5719-llvm-8f94ac6922f46afb9dcd97ab30b4c4c3845debd4.tar.gz bcm5719-llvm-8f94ac6922f46afb9dcd97ab30b4c4c3845debd4.zip | |
Adding a fixit for includes that cannot be found with angle brackets, but can be found with quoted strings instead. Implements PR13201.
llvm-svn: 160406
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticLexKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 25 | ||||
| -rw-r--r-- | clang/test/FixIt/fixit-include.c | 13 | ||||
| -rw-r--r-- | clang/test/FixIt/fixit-include.h | 1 |
4 files changed, 38 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 77b7f428723..1d55d6e50d4 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -279,6 +279,8 @@ def note_macro_here : Note<"macro %0 defined here">; def err_pp_invalid_directive : Error<"invalid preprocessing directive">; def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal; +def err_pp_file_not_found_not_fatal : Error< + "'%0' file not found with <angled> include; use \"quotes\" instead">; def err_pp_error_opening_file : Error< "error opening file '%0': %1">, DefaultFatal; def err_pp_empty_filename : Error<"empty filename">; diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index a6b7b52624e..74b9cbc881a 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1390,9 +1390,28 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } if (File == 0) { - if (!SuppressIncludeNotFoundError) - Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; - return; + if (!SuppressIncludeNotFoundError) { + // If the file could not be located and it was included via angle + // brackets, we can attempt a lookup as though it were a quoted path to + // provide the user with a possible fixit. + if (isAngled) { + File = LookupFile(Filename, false, LookupFrom, CurDir, + Callbacks ? &SearchPath : 0, + Callbacks ? &RelativePath : 0, + getLangOpts().Modules ? &SuggestedModule : 0); + if (File) { + SourceRange Range(FilenameTok.getLocation(), CharEnd); + Diag(FilenameTok, diag::err_pp_file_not_found_not_fatal) << + Filename << + FixItHint::CreateReplacement(Range, "\"" + Filename.str() + "\""); + } + } + // If the file is still not found, just go with the vanilla diagnostic + if (!File) + Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; + } + if (!File) + return; } // If we are supposed to import a module rather than including the header, diff --git a/clang/test/FixIt/fixit-include.c b/clang/test/FixIt/fixit-include.c new file mode 100644 index 00000000000..9da9409a7ef --- /dev/null +++ b/clang/test/FixIt/fixit-include.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -Wall -pedantic -verify %s
+// RUN: cp %s %t
+// RUN: cp %S/fixit-include.h %T
+// RUN: not %clang_cc1 -fsyntax-only -fixit %t
+// RUN: %clang_cc1 -Wall -pedantic %t
+
+#include <fixit-include.h> // expected-error {{'fixit-include.h' file not found with <angled> include; use "quotes" instead}}
+
+#pragma does_not_exist // expected-warning {{unknown pragma ignored}}
+
+int main( void ) {
+ return 0;
+}
diff --git a/clang/test/FixIt/fixit-include.h b/clang/test/FixIt/fixit-include.h new file mode 100644 index 00000000000..6a22d2e88eb --- /dev/null +++ b/clang/test/FixIt/fixit-include.h @@ -0,0 +1 @@ +// This file is purposefully left empty
|

