r229188 - [modules] If we have a choice between including a file textually and importing
Richard Smith
richard-llvm at metafoo.co.uk
Fri Feb 13 15:50:20 PST 2015
Author: rsmith
Date: Fri Feb 13 17:50:20 2015
New Revision: 229188
URL: http://llvm.org/viewvc/llvm-project?rev=229188&view=rev
Log:
[modules] If we have a choice between including a file textually and importing
a prebuilt form from a module, prefer the modular form, all else being equal.
Added:
cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/
cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/a.h
cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map1
cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map2
cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map3
cfe/trunk/test/Modules/header-in-multiple-maps.cpp
Modified:
cfe/trunk/lib/Lex/ModuleMap.cpp
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=229188&r1=229187&r2=229188&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Feb 13 17:50:20 2015
@@ -314,6 +314,22 @@ void ModuleMap::diagnoseHeaderInclusion(
}
}
+static bool isBetterKnownHeader(const ModuleMap::KnownHeader &New,
+ const ModuleMap::KnownHeader &Old) {
+ // Prefer a public header over a private header.
+ if ((New.getRole() & ModuleMap::PrivateHeader) !=
+ (Old.getRole() & ModuleMap::PrivateHeader))
+ return !(New.getRole() & ModuleMap::PrivateHeader);
+
+ // Prefer a non-textual header over a textual header.
+ if ((New.getRole() & ModuleMap::TextualHeader) !=
+ (Old.getRole() & ModuleMap::TextualHeader))
+ return !(New.getRole() & ModuleMap::TextualHeader);
+
+ // Don't have a reason to choose between these. Just keep the first one.
+ return false;
+}
+
ModuleMap::KnownHeader
ModuleMap::findModuleForHeader(const FileEntry *File,
Module *RequestingModule,
@@ -348,8 +364,7 @@ ModuleMap::findModuleForHeader(const Fil
!directlyUses(RequestingModule, I->getModule()))
continue;
- // Prefer a public header over a private header.
- if (!Result || (Result.getRole() & ModuleMap::PrivateHeader))
+ if (!Result || isBetterKnownHeader(*I, Result))
Result = *I;
}
return MakeResult(Result);
Added: cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/a.h?rev=229188&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/a.h Fri Feb 13 17:50:20 2015
@@ -0,0 +1 @@
+struct A {};
Added: cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map1
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map1?rev=229188&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map1 (added)
+++ cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map1 Fri Feb 13 17:50:20 2015
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "a.h" }
+module c { textual header "a.h" }
Added: cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map2
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map2?rev=229188&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map2 (added)
+++ cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map2 Fri Feb 13 17:50:20 2015
@@ -0,0 +1,3 @@
+module a { textual header "a.h" }
+module b { header "a.h" }
+module c { header "a.h" }
Added: cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map3
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map3?rev=229188&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map3 (added)
+++ cfe/trunk/test/Modules/Inputs/header-in-multiple-maps/map3 Fri Feb 13 17:50:20 2015
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { textual header "a.h" }
+module c { header "a.h" }
Added: cfe/trunk/test/Modules/header-in-multiple-maps.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/header-in-multiple-maps.cpp?rev=229188&view=auto
==============================================================================
--- cfe/trunk/test/Modules/header-in-multiple-maps.cpp (added)
+++ cfe/trunk/test/Modules/header-in-multiple-maps.cpp Fri Feb 13 17:50:20 2015
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map1 -verify %s
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map2 -verify %s
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map3 -verify %s
+// expected-no-diagnostics
+
+#include "a.h"
+#include "a.h"
+A *p;
More information about the cfe-commits
mailing list