From: Chuanqi Xu Date: Wed, 15 Feb 2023 03:29:29 +0000 (+0800) Subject: [NFC] Refactor ModuleDeclStateTest to make it not dependent on Frontend X-Git-Tag: upstream/17.0.6~17467 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54cf24dc6e6317f7a77f8a320f1fbccc31ea7291;p=platform%2Fupstream%2Fllvm.git [NFC] Refactor ModuleDeclStateTest to make it not dependent on Frontend Required in https://reviews.llvm.org/D137526. And it is indeed odd that LexTest depends on ClangFrontend. --- diff --git a/clang/unittests/Lex/CMakeLists.txt b/clang/unittests/Lex/CMakeLists.txt index 64ff794..aead76c 100644 --- a/clang/unittests/Lex/CMakeLists.txt +++ b/clang/unittests/Lex/CMakeLists.txt @@ -18,7 +18,6 @@ clang_target_link_libraries(LexTests PRIVATE clangAST clangBasic - clangFrontend clangLex clangParse clangSema diff --git a/clang/unittests/Lex/ModuleDeclStateTest.cpp b/clang/unittests/Lex/ModuleDeclStateTest.cpp index 246d653..ed69438 100644 --- a/clang/unittests/Lex/ModuleDeclStateTest.cpp +++ b/clang/unittests/Lex/ModuleDeclStateTest.cpp @@ -13,7 +13,6 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" -#include "clang/Frontend/CompilerInvocation.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" @@ -57,23 +56,25 @@ protected: ModuleDeclStateTest() : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), - SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions), Invocation() { + SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) { TargetOpts->Triple = "x86_64-unknown-linux-gnu"; Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); } - LangOptions &getLangOpts(ArrayRef CommandLineArgs) { - CompilerInvocation::CreateFromArgs(Invocation, CommandLineArgs, Diags); - return *Invocation.getLangOpts(); - } - std::unique_ptr - getPreprocessor(const char *source, ArrayRef CommandLineArgs) { + getPreprocessor(const char *source, Language Lang) { std::unique_ptr Buf = llvm::MemoryBuffer::getMemBuffer(source); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); - LangOptions &LangOpts = getLangOpts(CommandLineArgs); + std::vector Includes; + LangOptions::setLangDefaults(LangOpts, Lang, Target->getTriple(), Includes, LangStandard::lang_cxx20); + LangOpts.CPlusPlusModules = true; + if (Lang != Language::CXX) { + LangOpts.Modules = true; + LangOpts.ImplicitModules = true; + } + HeaderInfo.emplace(std::make_shared(), SourceMgr, Diags, LangOpts, Target.get()); @@ -104,7 +105,7 @@ protected: SourceManager SourceMgr; std::shared_ptr TargetOpts; IntrusiveRefCntPtr Target; - CompilerInvocation Invocation; + LangOptions LangOpts; TrivialModuleLoader ModLoader; std::optional HeaderInfo; }; @@ -113,7 +114,7 @@ TEST_F(ModuleDeclStateTest, NamedModuleInterface) { const char *source = R"( export module foo; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -132,7 +133,7 @@ TEST_F(ModuleDeclStateTest, NamedModuleImplementation) { const char *source = R"( module foo; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -151,7 +152,7 @@ TEST_F(ModuleDeclStateTest, ModuleImplementationPartition) { const char *source = R"( module foo:part; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -170,7 +171,7 @@ TEST_F(ModuleDeclStateTest, ModuleInterfacePartition) { const char *source = R"( export module foo:part; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -189,7 +190,7 @@ TEST_F(ModuleDeclStateTest, ModuleNameWithDot) { const char *source = R"( export module foo.dot:part.dot; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -208,7 +209,7 @@ TEST_F(ModuleDeclStateTest, NotModule) { const char *source = R"( // export module foo:part; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {}; preprocess(*PP, @@ -234,7 +235,7 @@ import "HU"; import M; import :another; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {true, true}; preprocess(*PP, @@ -261,7 +262,7 @@ import "HU"; import M; import :another; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {true, true}; preprocess(*PP, @@ -287,7 +288,7 @@ import M; // We can't import a partition in non-module TU. import :another; )"; - std::unique_ptr PP = getPreprocessor(source, "-std=c++20"); + std::unique_ptr PP = getPreprocessor(source, Language::CXX); std::initializer_list ImportKinds = {true}; preprocess(*PP, @@ -305,9 +306,7 @@ TEST_F(ModuleDeclStateTest, ImportAClangNamedModule) { const char *source = R"( @import anything; )"; - std::unique_ptr PP = - getPreprocessor(source, {"-fmodules", "-fimplicit-module-maps", "-x", - "objective-c++", "-std=c++20"}); + std::unique_ptr PP = getPreprocessor(source, Language::ObjCXX); std::initializer_list ImportKinds = {false}; preprocess(*PP, @@ -329,9 +328,7 @@ import M; @import another; import M2; )"; - std::unique_ptr PP = - getPreprocessor(source, {"-fmodules", "-fimplicit-module-maps", "-x", - "objective-c++", "-std=c++20"}); + std::unique_ptr PP = getPreprocessor(source, Language::ObjCXX); std::initializer_list ImportKinds = {false, true, false, true}; preprocess(*PP,