r335780 - [Modules][ObjC] Warn on the use of '@import' in framework headers
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 27 13:29:37 PDT 2018
Author: bruno
Date: Wed Jun 27 13:29:36 2018
New Revision: 335780
URL: http://llvm.org/viewvc/llvm-project?rev=335780&view=rev
Log:
[Modules][ObjC] Warn on the use of '@import' in framework headers
Using @import in framework headers inhibit the use of such headers
when not using modules, this is specially bad for headers that end
up in the SDK (or any other system framework). Add a warning to give
users some indication that this is discouraged.
rdar://problem/39192894
Added:
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/A.h
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/module.modulemap
cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/module.modulemap
cfe/trunk/test/Modules/at-import-in-framework-header.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/VFS/umbrella-mismatch.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=335780&r1=335779&r2=335780&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Jun 27 13:29:36 2018
@@ -34,6 +34,7 @@ def AutoImport : DiagGroup<"auto-import"
def FrameworkHdrQuotedInclude : DiagGroup<"quoted-include-in-framework-header">;
def FrameworkIncludePrivateFromPublic :
DiagGroup<"framework-include-private-from-public">;
+def FrameworkHdrAtImport : DiagGroup<"atimport-in-framework-header">;
def CXX14BinaryLiteral : DiagGroup<"c++14-binary-literal">;
def CXXPre14CompatBinaryLiteral : DiagGroup<"c++98-c++11-compat-binary-literal">;
def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=335780&r1=335779&r2=335780&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Jun 27 13:29:36 2018
@@ -248,6 +248,11 @@ def err_unexpected_at : Error<"unexpecte
def err_atimport : Error<
"use of '@import' when modules are disabled">;
+def warn_atimport_in_framework_header : Warning<
+ "use of '@import' in framework header is discouraged, "
+ "including this header requires -fmodules">,
+ InGroup<FrameworkHdrAtImport>;
+
def err_invalid_reference_qualifier_application : Error<
"'%0' qualifier may not be applied to a reference">;
def err_illegal_decl_reference_to_reference : Error<
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=335780&r1=335779&r2=335780&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Jun 27 13:29:36 2018
@@ -20,6 +20,7 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
+#include "llvm/Support/Path.h"
using namespace clang;
@@ -2123,6 +2124,7 @@ Decl *Parser::ParseModuleImport(SourceLo
assert((AtLoc.isInvalid() ? Tok.is(tok::kw_import)
: Tok.isObjCAtKeyword(tok::objc_import)) &&
"Improper start to module import");
+ bool IsObjCAtImport = Tok.isObjCAtKeyword(tok::objc_import);
SourceLocation ImportLoc = ConsumeToken();
SourceLocation StartLoc = AtLoc.isInvalid() ? ImportLoc : AtLoc;
@@ -2146,6 +2148,16 @@ Decl *Parser::ParseModuleImport(SourceLo
if (Import.isInvalid())
return nullptr;
+ // Using '@import' in framework headers requires modules to be enabled so that
+ // the header is parseable. Emit a warning to make the user aware.
+ if (IsObjCAtImport && AtLoc.isValid()) {
+ auto &SrcMgr = PP.getSourceManager();
+ auto *FE = SrcMgr.getFileEntryForID(SrcMgr.getFileID(AtLoc));
+ if (FE && llvm::sys::path::parent_path(FE->getDir()->getName())
+ .endswith(".framework"))
+ Diags.Report(AtLoc, diag::warn_atimport_in_framework_header);
+ }
+
return Import.get();
}
Added: cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/A.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/A.h?rev=335780&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/A.h (added)
+++ cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Headers/A.h Wed Jun 27 13:29:36 2018
@@ -0,0 +1,2 @@
+ at import B;
+int foo();
Added: cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/module.modulemap?rev=335780&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/A.framework/Modules/module.modulemap Wed Jun 27 13:29:36 2018
@@ -0,0 +1,4 @@
+// at-import-in-framework-header/A.framework/Modules/module.modulemap
+framework module A {
+ header "A.h"
+}
Added: cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/module.modulemap?rev=335780&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/at-import-in-framework-header/module.modulemap Wed Jun 27 13:29:36 2018
@@ -0,0 +1,2 @@
+// at-import-in-framework-header/module.modulemap
+module B {}
Added: cfe/trunk/test/Modules/at-import-in-framework-header.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/at-import-in-framework-header.m?rev=335780&view=auto
==============================================================================
--- cfe/trunk/test/Modules/at-import-in-framework-header.m (added)
+++ cfe/trunk/test/Modules/at-import-in-framework-header.m Wed Jun 27 13:29:36 2018
@@ -0,0 +1,17 @@
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir %t
+
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN: -F%S/Inputs/at-import-in-framework-header -I%S/Inputs/at-import-in-framework-header \
+// RUN: -Watimport-in-framework-header -fsyntax-only %s \
+// RUN: 2>%t/stderr
+// RUN: FileCheck --input-file=%t/stderr %s
+
+// CHECK: use of '@import' in framework header is discouraged
+
+#import <A/A.h>
+
+int bar() { return foo(); }
+
Modified: cfe/trunk/test/VFS/umbrella-mismatch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/umbrella-mismatch.m?rev=335780&r1=335779&r2=335780&view=diff
==============================================================================
--- cfe/trunk/test/VFS/umbrella-mismatch.m (original)
+++ cfe/trunk/test/VFS/umbrella-mismatch.m Wed Jun 27 13:29:36 2018
@@ -1,7 +1,7 @@
// RUN: rm -rf %t
// RUN: sed -e "s;INPUT_DIR;%/S/Inputs;g" -e "s;OUT_DIR;%/S/Inputs;g" %S/Inputs/vfsoverlay.yaml > %t.yaml
-// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ivfsoverlay %t.yaml -F %S/Inputs -fsyntax-only %s -verify
-// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs -fsyntax-only %s -verify
+// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ivfsoverlay %t.yaml -F %S/Inputs -fsyntax-only %s -Wno-atimport-in-framework-header -verify
+// RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs -fsyntax-only %s -Wno-atimport-in-framework-header -verify
// expected-no-diagnostics
@import UsesFoo;
More information about the cfe-commits
mailing list