From 55f7e00afc56c68421220d60d29c079b58fe9c79 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 15 Mar 2023 09:21:41 -0400 Subject: [libclang] Add index option to store preambles in memory This commit allows libclang API users to opt into storing PCH in memory instead of temporary files. The option can be set only during CXIndex construction to avoid multithreading issues and confusion or bugs if some preambles are stored in temporary files and others - in memory. The added API works as expected in KDevelop: https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/283 Differential Revision: https://reviews.llvm.org/D145974 --- clang/unittests/libclang/LibclangTest.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/unittests/libclang/LibclangTest.cpp') diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index 662377c..ca762eb 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/unittests/libclang/LibclangTest.cpp @@ -479,6 +479,7 @@ protected: }; class LibclangSetPreambleStoragePathTest : public LibclangPreambleStorageTest { + virtual bool StorePreamblesInMemory() { return false; } virtual const char *PreambleStoragePath() = 0; protected: @@ -487,6 +488,7 @@ protected: CXIndexOptions Opts{}; Opts.Size = sizeof(CXIndexOptions); + Opts.StorePreamblesInMemory = StorePreamblesInMemory(); Opts.PreambleStoragePath = PreambleStoragePath(); Index = clang_createIndexWithOptions(&Opts); ASSERT_TRUE(Index); @@ -506,6 +508,19 @@ class LibclangPreambleDirPreambleStoragePathTest const char *PreambleStoragePath() override { return PreambleDir.c_str(); } }; +class LibclangStoreInMemoryNullPreambleStoragePathTest + : public LibclangNullPreambleStoragePathTest { + bool StorePreamblesInMemory() override { return true; } +}; +class LibclangStoreInMemoryEmptyPreambleStoragePathTest + : public LibclangEmptyPreambleStoragePathTest { + bool StorePreamblesInMemory() override { return true; } +}; +class LibclangStoreInMemoryPreambleDirPreambleStoragePathTest + : public LibclangPreambleDirPreambleStoragePathTest { + bool StorePreamblesInMemory() override { return true; } +}; + TEST_F(LibclangNotOverriddenPreambleStoragePathTest, CountPreambles) { CountPreamblesInPreambleDir(0); } @@ -518,6 +533,16 @@ TEST_F(LibclangEmptyPreambleStoragePathTest, CountPreambles) { TEST_F(LibclangPreambleDirPreambleStoragePathTest, CountPreambles) { CountPreamblesInPreambleDir(1); } +TEST_F(LibclangStoreInMemoryNullPreambleStoragePathTest, CountPreambles) { + CountPreamblesInPreambleDir(0); +} +TEST_F(LibclangStoreInMemoryEmptyPreambleStoragePathTest, CountPreambles) { + CountPreamblesInPreambleDir(0); +} +TEST_F(LibclangStoreInMemoryPreambleDirPreambleStoragePathTest, + CountPreambles) { + CountPreamblesInPreambleDir(0); +} TEST_F(LibclangParseTest, AllSkippedRanges) { std::string Header = "header.h", Main = "main.cpp"; -- cgit v1.1