]> granicus.if.org Git - clang/commitdiff
implement rdar://7520940: published framework headers should
authorChris Lattner <sabre@nondot.org>
Sun, 10 Jan 2010 00:24:58 +0000 (00:24 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 10 Jan 2010 00:24:58 +0000 (00:24 +0000)
import other headers within the same framework with the full
framework path, not with a relative include.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93083 91177308-0d34-0410-b5e6-96231b3b80d8

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/Headers/bar.h [new file with mode: 0644]
test/Preprocessor/foo.framework/Headers/foo.h [new file with mode: 0644]
test/Preprocessor/framework-include.m [new file with mode: 0644]

index d8b5f2dad3c96c1772afb75bc453cf30339190ca..d79091a1f6b6906e853f8738162af22e63edd6fb 100644 (file)
@@ -169,6 +169,9 @@ def err_pp_hash_error : Error<"#error%0">;
 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>">;
index a73d829f9e57ba0448df8aa9f9b0b0348a8f586e..5669a632078ff322cb3cbba0355e059dfbefa33b 100644 (file)
@@ -698,7 +698,8 @@ public:
   /// 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
index 9e3d283d888613a6088b09f1486d5a9449930fe6..a719a541a36342be24639818d23311540b735285 100644 (file)
@@ -406,6 +406,7 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() {
 /// 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 *Preprocessor::LookupFile(const char *FilenameStart,
   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 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
   // 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))
index 80202ddb6d0da205d758eea0588e5c0f15d364d8..1c8af8385b91bd3e042596f9a85db423878487ba 100644 (file)
@@ -561,7 +561,8 @@ static bool EvaluateHasIncludeCommon(bool &Result, Token &Tok,
   // 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;
index 8b46f716910c943526839ecc8a7dd601fc92a068..74692faf42c56e0dd20a5fd0cc32a2cc00172fc3 100644 (file)
@@ -302,6 +302,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
   // 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)
diff --git a/test/Preprocessor/foo.framework/Headers/bar.h b/test/Preprocessor/foo.framework/Headers/bar.h
new file mode 100644 (file)
index 0000000..574e851
--- /dev/null
@@ -0,0 +1,3 @@
+
+int y;
+
diff --git a/test/Preprocessor/foo.framework/Headers/foo.h b/test/Preprocessor/foo.framework/Headers/foo.h
new file mode 100644 (file)
index 0000000..1b3f834
--- /dev/null
@@ -0,0 +1,4 @@
+#include "bar.h"
+
+int x;
+
diff --git a/test/Preprocessor/framework-include.m b/test/Preprocessor/framework-include.m
new file mode 100644 (file)
index 0000000..3de378e
--- /dev/null
@@ -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>
+