From 560b361a406f10fcddd36007ce5ae6ded3558ded Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 14 May 2015 00:45:20 +0000 Subject: [PATCH] [modules] Fix a #include cycle when building a module for our builtin headers. 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 | 2 +- lib/Headers/xmmintrin.h | 2 +- lib/Serialization/ASTWriter.cpp | 14 +++++++++----- test/Headers/Inputs/include/stdlib.h | 2 ++ test/Headers/xmmintrin.c | 12 ++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test/Headers/Inputs/include/stdlib.h diff --git a/lib/Headers/module.modulemap b/lib/Headers/module.modulemap index bb2ca95212..ac5876f8d7 100644 --- a/lib/Headers/module.modulemap +++ b/lib/Headers/module.modulemap @@ -49,7 +49,7 @@ module _Builtin_intrinsics [system] [extern_c] { explicit module sse { requires sse export mmx - export * // note: for hackish dependency + export sse2 // note: for hackish dependency header "xmmintrin.h" } diff --git a/lib/Headers/xmmintrin.h b/lib/Headers/xmmintrin.h index d1afe81601..3a6b95e8bf 100644 --- a/lib/Headers/xmmintrin.h +++ b/lib/Headers/xmmintrin.h @@ -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 #endif diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 0e6e558839..29a88a13d3 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -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 index 0000000000..296b6239f6 --- /dev/null +++ b/test/Headers/Inputs/include/stdlib.h @@ -0,0 +1,2 @@ +#pragma once +typedef __SIZE_TYPE__ size_t; diff --git a/test/Headers/xmmintrin.c b/test/Headers/xmmintrin.c index c426f34d06..76fff0db77 100644 --- a/test/Headers/xmmintrin.c +++ b/test/Headers/xmmintrin.c @@ -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 @@ -11,3 +16,10 @@ __m64 test_mm_cvtps_pi16(__m128 a) { return _mm_cvtps_pi16(a); } + +// Make sure that including also makes '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); +} + -- 2.40.0