]> granicus.if.org Git - clang/commitdiff
[modules] Fix a #include cycle when building a module for our builtin headers.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 May 2015 00:45:20 +0000 (00:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 May 2015 00:45:20 +0000 (00:45 +0000)
xmmintrin.h includes emmintrin.h and vice versa if SSE2 is enabled. We break
this cycle for a modules build, and instead make the xmmintrin.h module
re-export the immintrin.h module. Also included is a fix for an assert in the
serialization code if a module exports another module that was declared later
in the same module map.

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

lib/Headers/module.modulemap
lib/Headers/xmmintrin.h
lib/Serialization/ASTWriter.cpp
test/Headers/Inputs/include/stdlib.h [new file with mode: 0644]
test/Headers/xmmintrin.c

index bb2ca95212d81d519afc997898f46db7c7a823e8..ac5876f8d726467082e5dfeb2a0259665c16143c 100644 (file)
@@ -49,7 +49,7 @@ module _Builtin_intrinsics [system] [extern_c] {
     explicit module sse {
       requires sse
       export mmx
-      export * // note: for hackish <emmintrin.h> dependency
+      export sse2 // note: for hackish <emmintrin.h> dependency
       header "xmmintrin.h"
     }
 
index d1afe81601c326234979d8a27e021978367fea82..3a6b95e8bfeab6801e46b7ebccba7fad1376bbcb 100644 (file)
@@ -994,7 +994,7 @@ do { \
 #define _m_ _mm_
 
 /* Ugly hack for backwards-compatibility (compatible with gcc) */
-#ifdef __SSE2__
+#if defined(__SSE2__) && !__has_feature(modules)
 #include <emmintrin.h>
 #endif
 
index 0e6e5588390eb3e86ce9ca1e4075f5944359f854..29a88a13d38a5cddd8f224108760e7315136c2a1 100644 (file)
@@ -2496,8 +2496,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
       Record.clear();
       for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) {
         if (Module *Exported = Mod->Exports[I].getPointer()) {
-          unsigned ExportedID = SubmoduleIDs[Exported];
-          assert(ExportedID > 0 && "Unknown submodule ID?");
+          unsigned ExportedID = getSubmoduleID(Exported);
           Record.push_back(ExportedID);
         } else {
           Record.push_back(0);
@@ -2548,9 +2547,14 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
   }
   
   Stream.ExitBlock();
-  
-  assert((NextSubmoduleID - FirstSubmoduleID
-            == getNumberOfModules(WritingModule)) && "Wrong # of submodules");
+
+  // FIXME: This can easily happen, if we have a reference to a submodule that
+  // did not result in us loading a module file for that submodule. For
+  // instance, a cross-top-level-module 'conflict' declaration will hit this.
+  assert((NextSubmoduleID - FirstSubmoduleID ==
+          getNumberOfModules(WritingModule)) &&
+         "Wrong # of submodules; found a reference to a non-local, "
+         "non-imported submodule?");
 }
 
 serialization::SubmoduleID 
diff --git a/test/Headers/Inputs/include/stdlib.h b/test/Headers/Inputs/include/stdlib.h
new file mode 100644 (file)
index 0000000..296b623
--- /dev/null
@@ -0,0 +1,2 @@
+#pragma once
+typedef __SIZE_TYPE__ size_t;
index c426f34d06ea8f4a832b9a64ab23de8460e842c5..76fff0db77fda616e70bf34316622a99bbecea67 100644 (file)
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-macosx10.9.0 -emit-llvm -o - | FileCheck %s
+//
+// RUN: rm -rf %t
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-macosx10.9.0 -emit-llvm -o - \
+// RUN:     -fmodules -fmodules-cache-path=%t -isystem %S/Inputs/include \
+// RUN:     | FileCheck %s
 
 #include <xmmintrin.h>
 
 __m64 test_mm_cvtps_pi16(__m128 a) {
   return _mm_cvtps_pi16(a);
 }
+
+// Make sure that including <xmmintrin.h> also makes <emmintrin.h>'s content available.
+// This is an ugly hack for GCC compatibility.
+__m128 test_xmmintrin_provides_emmintrin(__m128d __a, __m128d __b) {
+  return _mm_add_sd(__a, __b);
+}
+