[cfe-commits] r145500 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticLexKinds.td lib/Lex/PPDirectives.cpp test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h test/Modules/auto-module-import.c
Douglas Gregor
dgregor at apple.com
Wed Nov 30 10:02:36 PST 2011
Author: dgregor
Date: Wed Nov 30 12:02:36 2011
New Revision: 145500
URL: http://llvm.org/viewvc/llvm-project?rev=145500&view=rev
Log:
Introduce an opt-in warning indicating when the compiler is treating
an #include/#import as a module import.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h
cfe/trunk/test/Modules/auto-module-import.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=145500&r1=145499&r2=145500&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Nov 30 12:02:36 2011
@@ -25,6 +25,7 @@
def : DiagGroup<"attributes">;
def : DiagGroup<"bad-function-cast">;
def Availability : DiagGroup<"availability">;
+def AutoImport : DiagGroup<"auto-import">;
def BoolConversions : DiagGroup<"bool-conversions">;
def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
def CXXCompat: DiagGroup<"c++-compat">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=145500&r1=145499&r2=145500&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Wed Nov 30 12:02:36 2011
@@ -400,4 +400,8 @@
def err_mmap_umbrella_clash : Error<
"umbrella header for module '%0' already covers this directory">;
+def warn_auto_module_import : Warning<
+ "treating #%select{include|import|include_next|__include_macros}0 as an "
+ "import of module '%1'">, InGroup<AutoImport>, DefaultIgnore;
+
}
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=145500&r1=145499&r2=145500&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Nov 30 12:02:36 2011
@@ -22,6 +22,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -1208,6 +1209,7 @@
llvm::SmallString<128> FilenameBuffer;
StringRef Filename;
SourceLocation End;
+ SourceLocation CharEnd; // the end of this directive, in characters
switch (FilenameTok.getKind()) {
case tok::eod:
@@ -1218,6 +1220,7 @@
case tok::string_literal:
Filename = getSpelling(FilenameTok, FilenameBuffer);
End = FilenameTok.getLocation();
+ CharEnd = End.getLocWithOffset(Filename.size());
break;
case tok::less:
@@ -1227,6 +1230,7 @@
if (ConcatenateIncludeName(FilenameBuffer, End))
return; // Found <eod> but no ">"? Diagnostic already emitted.
Filename = FilenameBuffer.str();
+ CharEnd = getLocForEndOfToken(End);
break;
default:
Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
@@ -1288,6 +1292,44 @@
FilenameTok.getLocation()));
std::reverse(Path.begin(), Path.end());
+ // Warn that we're replacing the include/import with a module import.
+ llvm::SmallString<128> PathString;
+ for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+ if (I)
+ PathString += '.';
+ PathString += Path[I].first->getName();
+ }
+ int IncludeKind = 0;
+
+ switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
+ case tok::pp_include:
+ IncludeKind = 0;
+ break;
+
+ case tok::pp_import:
+ IncludeKind = 1;
+ break;
+
+ case tok::pp_include_next:
+ IncludeKind = 2;
+ break;
+
+ case tok::pp___include_macros:
+ IncludeKind = 3;
+ break;
+
+ default:
+ llvm_unreachable("unknown include directive kind");
+ break;
+ }
+
+ CharSourceRange ReplaceRange(SourceRange(HashLoc, CharEnd),
+ /*IsTokenRange=*/false);
+ Diag(HashLoc, diag::warn_auto_module_import)
+ << IncludeKind << PathString
+ << FixItHint::CreateReplacement(ReplaceRange,
+ "__import_module__ " + PathString.str().str() + ";");
+
// Load the module.
TheModuleLoader.loadModule(IncludeTok.getLocation(), Path);
return;
Modified: cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h?rev=145500&r1=145499&r2=145500&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h (original)
+++ cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/Headers/DependsOnModule.h Wed Nov 30 12:02:36 2011
@@ -1,4 +1,4 @@
-#include <Module/Module.h>
+#include <Module/Module.h> //expected-warning{{treating #include as an import of module 'Module'}}
#define DEPENDS_ON_MODULE 1
#__private_macro__ DEPENDS_ON_MODULE
Modified: cfe/trunk/test/Modules/auto-module-import.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/auto-module-import.c?rev=145500&r1=145499&r2=145500&view=diff
==============================================================================
--- cfe/trunk/test/Modules/auto-module-import.c (original)
+++ cfe/trunk/test/Modules/auto-module-import.c Wed Nov 30 12:02:36 2011
@@ -1,8 +1,8 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %t -fauto-module-import -F %S/Inputs %s -verify
+// RUN: %clang_cc1 -x objective-c -Wauto-import -fmodule-cache-path %t -fauto-module-import -F %S/Inputs %s -verify
-#include <DependsOnModule/DependsOnModule.h>
+#include <DependsOnModule/DependsOnModule.h> // expected-warning{{treating #include as an import of module 'DependsOnModule'}}
#ifdef MODULE_H_MACRO
# error MODULE_H_MACRO should have been hidden
More information about the cfe-commits
mailing list