]> granicus.if.org Git - clang/commitdiff
Treat module headers wrapped by our builtin headers as implicitly being textual
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Oct 2016 01:08:55 +0000 (01:08 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Oct 2016 01:08:55 +0000 (01:08 +0000)
headers. We previously got this check backwards and treated the wrapper header
as being textual.

This is important because our wrapper headers sometimes inject macros into the
system headers that they #include_next, and sometimes replace them entirely.

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

lib/Lex/ModuleMap.cpp
test/Modules/Inputs/System/usr/include/stdbool.h
test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stddef.h
test/Modules/cstd.m

index 6a261a1154857bcfb07bcc75aeb070229093e2b8..2b6b78aceec52c55fcf639489038cd0433eb0243 100644 (file)
@@ -1881,16 +1881,20 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken,
       Module::Header H = {RelativePathName.str(), File};
       Map.excludeHeader(ActiveModule, H);
     } else {
-      // If there is a builtin counterpart to this file, add it now as a textual
-      // header, so it can be #include_next'd by the wrapper header, and can
-      // receive macros from the wrapper header.
+      // If there is a builtin counterpart to this file, add it now so it can
+      // wrap the system header.
       if (BuiltinFile) {
         // FIXME: Taking the name from the FileEntry is unstable and can give
         // different results depending on how we've previously named that file
         // in this build.
         Module::Header H = { BuiltinFile->getName(), BuiltinFile };
-        Map.addHeader(ActiveModule, H, ModuleMap::ModuleHeaderRole(
-                                           Role | ModuleMap::TextualHeader));
+        Map.addHeader(ActiveModule, H, Role);
+
+        // If we have both a builtin and system version of the file, the
+        // builtin version may want to inject macros into the system header, so
+        // force the system header to be treated as a textual header in this
+        // case.
+        Role = ModuleMap::ModuleHeaderRole(Role | ModuleMap::TextualHeader);
       }
 
       // Record this header.
index 50be7543c42eecaeaf40efe2ff11d7a59c970246..760d7dc48efdd12bb7682d4be8f49e89e54f7449 100644 (file)
@@ -1 +1 @@
-#include_next <stdbool.h>
+// Testing hack: does not define bool/true/false.
index c211f99261ebd7888b596705abaca8ce6b457fa9..eca72412a651c29114b0d1ad76b4fcefd1a1a775 100644 (file)
@@ -1,2 +1 @@
 // stddef.h
-#include_next "stddef.h"
index 7df727d2efcb0968c2905d8dc8de48ca4ae310d2..2182140d5db0a99c81ce2c28ad73c16421388047 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
 
 @import uses_other_constants;
 const double other_value = DBL_MAX;