[cfe-commits] r93083 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td include/clang/Lex/Preprocessor.h lib/Lex/PPDirectives.cpp lib/Lex/PPMacroExpansion.cpp lib/Lex/Pragma.cpp test/Preprocessor/foo.framework/ test/Preprocessor/foo.framework/Headers/ test/Preprocessor/foo.framework/Headers/bar.h test/Preprocessor/foo.framework/Headers/foo.h test/Preprocessor/framework-include.m

Chris Lattner sabre at nondot.org
Sat Jan 9 16:24:59 PST 2010


Author: lattner
Date: Sat Jan  9 18:24:58 2010
New Revision: 93083

URL: http://llvm.org/viewvc/llvm-project?rev=93083&view=rev
Log:
implement rdar://7520940: published framework headers should
import other headers within the same framework with the full
framework path, not with a relative include.


Added:
    cfe/trunk/test/Preprocessor/foo.framework/
    cfe/trunk/test/Preprocessor/foo.framework/Headers/
    cfe/trunk/test/Preprocessor/foo.framework/Headers/bar.h
    cfe/trunk/test/Preprocessor/foo.framework/Headers/foo.h
    cfe/trunk/test/Preprocessor/framework-include.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=93083&r1=93082&r2=93083&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sat Jan  9 18:24:58 2010
@@ -169,6 +169,9 @@
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
 def err_pp_error_opening_file : Error<
   "error opening file '%0': %1">, DefaultFatal;
+def warn_pp_relative_include_from_framework : Warning<
+  "published framework headers should always #import headers within the "
+  "framework with framework paths">, InGroup<DiagGroup<"framework-headers">>;
 def err_pp_empty_filename : Error<"empty filename">;
 def err_pp_include_too_deep : Error<"#include nested too deeply">;
 def err_pp_expects_filename : Error<"expected \"FILENAME\" or <FILENAME>">;

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=93083&r1=93082&r2=93083&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Jan  9 18:24:58 2010
@@ -698,7 +698,8 @@
   /// return null on failure.  isAngled indicates whether the file reference is
   /// for system #include's or not (i.e. using <> instead of "").
   const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd,
-                              bool isAngled, const DirectoryLookup *FromDir,
+                              SourceLocation FilenameTokLoc, bool isAngled,
+                              const DirectoryLookup *FromDir,
                               const DirectoryLookup *&CurDir);
 
   /// GetCurLookup - The DirectoryLookup structure used to find the current

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=93083&r1=93082&r2=93083&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat Jan  9 18:24:58 2010
@@ -406,6 +406,7 @@
 /// for system #include's or not (i.e. using <> instead of "").
 const FileEntry *Preprocessor::LookupFile(const char *FilenameStart,
                                           const char *FilenameEnd,
+                                          SourceLocation FilenameTokLoc,
                                           bool isAngled,
                                           const DirectoryLookup *FromDir,
                                           const DirectoryLookup *&CurDir) {
@@ -433,7 +434,16 @@
   const FileEntry *FE =
     HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
                           isAngled, FromDir, CurDir, CurFileEnt);
-  if (FE) return FE;
+  if (FE) {
+    // Warn about normal quoted #include from framework headers.  Since
+    // framework headers are published (both public and private ones) they
+    // should not do relative searches, they should do an include relative to
+    // their framework.
+    if (!isAngled && CurDir && FilenameTokLoc.isValid() &&
+        CurDir->isFramework() && CurDir == CurDirLookup)
+      Diag(FilenameTokLoc, diag::warn_pp_relative_include_from_framework);
+    return FE;
+  }
 
   // Otherwise, see if this is a subframework header.  If so, this is relative
   // to one of the headers on the #include stack.  Walk the list of the current
@@ -1080,13 +1090,14 @@
   // Search include directories.
   const DirectoryLookup *CurDir;
   const FileEntry *File = LookupFile(FilenameStart, FilenameEnd,
+                                     FilenameTok.getLocation(),
                                      isAngled, LookupFrom, CurDir);
   if (File == 0) {
     Diag(FilenameTok, diag::err_pp_file_not_found)
        << std::string(FilenameStart, FilenameEnd);
     return;
   }
-
+  
   // Ask HeaderInfo if we should enter this #include file.  If not, #including
   // this file will have no effect.
   if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport))

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=93083&r1=93082&r2=93083&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Jan  9 18:24:58 2010
@@ -561,7 +561,8 @@
   // Search include directories.
   const DirectoryLookup *CurDir;
   const FileEntry *File = PP.LookupFile(FilenameStart, FilenameEnd,
-                                     isAngled, LookupFrom, CurDir);
+                                        SourceLocation(),// produce no warnings.
+                                        isAngled, LookupFrom, CurDir);
 
   // Get the result value.  Result = true means the file exists.
   Result = File != 0;

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=93083&r1=93082&r2=93083&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sat Jan  9 18:24:58 2010
@@ -302,6 +302,7 @@
   // Search include directories for this file.
   const DirectoryLookup *CurDir;
   const FileEntry *File = LookupFile(FilenameStart, FilenameEnd,
+                                     FilenameTok.getLocation(),
                                      isAngled, 0, CurDir);
   if (File == 0) {
     Diag(FilenameTok, diag::err_pp_file_not_found)

Added: cfe/trunk/test/Preprocessor/foo.framework/Headers/bar.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/foo.framework/Headers/bar.h?rev=93083&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/foo.framework/Headers/bar.h (added)
+++ cfe/trunk/test/Preprocessor/foo.framework/Headers/bar.h Sat Jan  9 18:24:58 2010
@@ -0,0 +1,3 @@
+
+int y;
+

Added: cfe/trunk/test/Preprocessor/foo.framework/Headers/foo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/foo.framework/Headers/foo.h?rev=93083&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/foo.framework/Headers/foo.h (added)
+++ cfe/trunk/test/Preprocessor/foo.framework/Headers/foo.h Sat Jan  9 18:24:58 2010
@@ -0,0 +1,4 @@
+#include "bar.h"
+
+int x;
+

Added: cfe/trunk/test/Preprocessor/framework-include.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/framework-include.m?rev=93083&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/framework-include.m (added)
+++ cfe/trunk/test/Preprocessor/framework-include.m Sat Jan  9 18:24:58 2010
@@ -0,0 +1,5 @@
+// RUN: %clang -E -F%S %s 2>&1 | grep "Headers/foo.h:1:10: warning: published framework headers should always #import headers within the framework with framework paths"
+
+// rdar://7520940
+#include <foo/foo.h>
+





More information about the cfe-commits mailing list