Author: Chuanqi Xu Date: 2024-04-30T14:28:11+08:00 New Revision: 6b961e2abfffd8b5a508b5958849b13b0feafa50
URL: https://github.com/llvm/llvm-project/commit/6b961e2abfffd8b5a508b5958849b13b0feafa50 DIFF: https://github.com/llvm/llvm-project/commit/6b961e2abfffd8b5a508b5958849b13b0feafa50.diff LOG: Revert "[C++20] [Modules] Don't skip pragma diagnostic mappings" and "[NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to generate module file for C++20 modules instead of PCHGenerator" This reverts commit fb21343473e33e9a886b42d2fe95d1cec1cd0030. and commit 18268ac0f48d93c2bcddb69732761971669c09ab. It looks like there are some problems about linking the compiler Added: Modified: clang/include/clang/Serialization/ASTWriter.h clang/lib/Frontend/FrontendActions.cpp clang/lib/Serialization/GeneratePCH.cpp clang/test/Modules/pr67893.cppm clang/test/Modules/search-partitions.cpp Removed: clang/test/Modules/pr75057.cppm ################################################################################ diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 4e433deaaf2dbc..6c45b7348b8552 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -928,30 +928,17 @@ class PCHGenerator : public SemaConsumer { bool hasEmittedPCH() const { return Buffer->IsComplete; } }; -class CXX20ModulesGenerator : public PCHGenerator { +class ReducedBMIGenerator : public PCHGenerator { protected: virtual Module *getEmittingModule(ASTContext &Ctx) override; - CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, - StringRef OutputFile, bool GeneratingReducedBMI); - public: - CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, - StringRef OutputFile) - : CXX20ModulesGenerator(PP, ModuleCache, OutputFile, - /*GeneratingReducedBMI=*/false) {} + ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, + StringRef OutputFile); void HandleTranslationUnit(ASTContext &Ctx) override; }; -class ReducedBMIGenerator : public CXX20ModulesGenerator { -public: - ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, - StringRef OutputFile) - : CXX20ModulesGenerator(PP, ModuleCache, OutputFile, - /*GeneratingReducedBMI=*/true) {} -}; - /// If we can elide the definition of \param D in reduced BMI. /// /// Generally, we can elide the definition of a declaration if it won't affect diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 454653a31534cd..04eb1041326713 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -272,10 +272,14 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction( std::unique_ptr<ASTConsumer> GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - std::vector<std::unique_ptr<ASTConsumer>> Consumers; - Consumers.push_back(std::make_unique<CXX20ModulesGenerator>( - CI.getPreprocessor(), CI.getModuleCache(), - CI.getFrontendOpts().OutputFile)); + CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true; + CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true; + CI.getHeaderSearchOpts().ModulesSkipPragmaDiagnosticMappings = true; + + std::vector<std::unique_ptr<ASTConsumer>> Consumers = + CreateMultiplexConsumer(CI, InFile); + if (Consumers.empty()) + return nullptr; if (CI.getFrontendOpts().GenReducedBMI && !CI.getFrontendOpts().ModuleOutputPath.empty()) { diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index 53dda5f9a38580..bed74399098d7f 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -88,32 +88,36 @@ ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() { return &Writer; } -CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP, - InMemoryModuleCache &ModuleCache, - StringRef OutputFile, - bool GeneratingReducedBMI) +ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP, + InMemoryModuleCache &ModuleCache, + StringRef OutputFile) : PCHGenerator( PP, ModuleCache, OutputFile, llvm::StringRef(), std::make_shared<PCHBuffer>(), /*Extensions=*/ArrayRef<std::shared_ptr<ModuleFileExtension>>(), /*AllowASTWithErrors*/ false, /*IncludeTimestamps=*/false, /*BuildingImplicitModule=*/false, /*ShouldCacheASTInMemory=*/false, - GeneratingReducedBMI) {} + /*GeneratingReducedBMI=*/true) {} -Module *CXX20ModulesGenerator::getEmittingModule(ASTContext &Ctx) { +Module *ReducedBMIGenerator::getEmittingModule(ASTContext &Ctx) { Module *M = Ctx.getCurrentNamedModule(); assert(M && M->isNamedModuleUnit() && - "CXX20ModulesGenerator should only be used with C++20 Named modules."); + "ReducedBMIGenerator should only be used with C++20 Named modules."); return M; } -void CXX20ModulesGenerator::HandleTranslationUnit(ASTContext &Ctx) { +void ReducedBMIGenerator::HandleTranslationUnit(ASTContext &Ctx) { + // We need to do this to make sure the size of reduced BMI not to be larger + // than full BMI. + // // FIMXE: We'd better to wrap such options to a new class ASTWriterOptions // since this is not about searching header really. + // FIXME2: We'd better to move the class writing full BMI with reduced BMI. HeaderSearchOptions &HSOpts = getPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts(); HSOpts.ModulesSkipDiagnosticOptions = true; HSOpts.ModulesSkipHeaderSearchPaths = true; + HSOpts.ModulesSkipPragmaDiagnosticMappings = true; PCHGenerator::HandleTranslationUnit(Ctx); diff --git a/clang/test/Modules/pr67893.cppm b/clang/test/Modules/pr67893.cppm index 95479193f8ea2b..58990cec01d666 100644 --- a/clang/test/Modules/pr67893.cppm +++ b/clang/test/Modules/pr67893.cppm @@ -5,7 +5,7 @@ // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/a.cppm \ // RUN: -emit-module-interface -o %t/a.pcm // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.cppm \ -// RUN: -emit-module-interface -fprebuilt-module-path=%t -o %t/m.pcm +// RUN: -emit-module-interface -fprebuilt-module-path=%t // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.pcm \ // RUN: -fprebuilt-module-path=%t -S -emit-llvm -o - | FileCheck %t/m.cppm diff --git a/clang/test/Modules/pr75057.cppm b/clang/test/Modules/pr75057.cppm deleted file mode 100644 index 374c324e9f495b..00000000000000 --- a/clang/test/Modules/pr75057.cppm +++ /dev/null @@ -1,62 +0,0 @@ -// RUN: rm -rf %t -// RUN: mkdir -p %t -// RUN: split-file %s %t -// -// Treat the behavior of using headers as baseline. -// RUN: %clang_cc1 -std=c++20 %t/use-header.cc -isystem %t -fsyntax-only -verify -// -// RUN: %clang_cc1 -std=c++20 %t/a.cppm -isystem %t -emit-module-interface -o %t/a.pcm -// RUN: %clang_cc1 -std=c++20 %t/use-module.cc -isystem %t -fmodule-file=a=%t/a.pcm -fsyntax-only -verify - -//--- sys.h -#ifndef SYS_H -#define SYS_H - -#pragma GCC system_header - -template <class C> -struct [[deprecated]] iterator {}; - -_Pragma("GCC diagnostic push") -_Pragma("GCC diagnostic ignored \"-Wdeprecated\"") -_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") - -template <class C> -struct reverse_iterator -: public iterator<C> {}; - -_Pragma("GCC diagnostic pop") - -template <class T> -class C { -public: - void i() { - reverse_iterator<T> i; - } -}; - -#endif - -//--- use-header.cc -// expected-no-diagnostics -// However, we see unexpected warnings -#include <sys.h> - -void use() { - C<int>().i(); -} - -//--- a.cppm -module; -#include <sys.h> -export module a; -export using ::iterator; -export using ::C; - -//--- use-module.cc -// expected-no-diagnostics -import a; - -void use() { - C<int>().i(); -} diff --git a/clang/test/Modules/search-partitions.cpp b/clang/test/Modules/search-partitions.cpp index 92f7c637c83384..92732958db94e6 100644 --- a/clang/test/Modules/search-partitions.cpp +++ b/clang/test/Modules/search-partitions.cpp @@ -11,7 +11,7 @@ // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition3.cpp \ // RUN: -o %t/A-Part3.pcm -// RUN: %clang_cc1 -std=c++20 %t/moduleA.cpp -fsyntax-only -verify \ +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/moduleA.cpp \ // RUN: -fprebuilt-module-path=%t // Test again with reduced BMI @@ -28,7 +28,9 @@ // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/partition3.cpp \ // RUN: -o %t/A-Part3.pcm -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/moduleA.cpp -fprebuilt-module-path=%t +// RUN: %clang_cc1 -std=c++20 -fsyntax-only %t/moduleA.cpp -fprebuilt-module-path=%t + +// expected-no-diagnostics //--- partition1.cpp export module A:Part1; @@ -48,7 +50,7 @@ export module A:Part3; int part3(); //--- moduleA.cpp -// expected-no-diagnostics + export module A; import :Part1; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits