[cfe-commits] r160406 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/PPDirectives.cpp test/FixIt/fixit-include.c test/FixIt/fixit-include.h

Aaron Ballman aaron at aaronballman.com
Tue Jul 17 16:19:16 PDT 2012


Author: aaronballman
Date: Tue Jul 17 18:19:16 2012
New Revision: 160406

URL: http://llvm.org/viewvc/llvm-project?rev=160406&view=rev
Log:
Adding a fixit for includes that cannot be found with angle brackets, but can be found with quoted strings instead.  Implements PR13201.

Added:
    cfe/trunk/test/FixIt/fixit-include.c
    cfe/trunk/test/FixIt/fixit-include.h
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=160406&r1=160405&r2=160406&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Jul 17 18:19:16 2012
@@ -279,6 +279,8 @@
 
 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">;

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=160406&r1=160405&r2=160406&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jul 17 18:19:16 2012
@@ -1390,9 +1390,28 @@
   }
   
   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,

Added: cfe/trunk/test/FixIt/fixit-include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-include.c?rev=160406&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-include.c (added)
+++ cfe/trunk/test/FixIt/fixit-include.c Tue Jul 17 18:19:16 2012
@@ -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;
+}

Added: cfe/trunk/test/FixIt/fixit-include.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-include.h?rev=160406&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-include.h (added)
+++ cfe/trunk/test/FixIt/fixit-include.h Tue Jul 17 18:19:16 2012
@@ -0,0 +1 @@
+// This file is purposefully left empty





More information about the cfe-commits mailing list