diff options
author | Igor Kushnir <igorkuo@gmail.com> | 2023-03-15 09:21:41 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2023-03-15 09:21:41 -0400 |
commit | 55f7e00afc56c68421220d60d29c079b58fe9c79 (patch) | |
tree | a17833891c04630995bdc4627e08252c5ca369ff /clang/unittests/libclang/LibclangTest.cpp | |
parent | 506fd6725166d2688b7d15b09f00da1abaa1f157 (diff) | |
download | llvm-55f7e00afc56c68421220d60d29c079b58fe9c79.zip llvm-55f7e00afc56c68421220d60d29c079b58fe9c79.tar.gz llvm-55f7e00afc56c68421220d60d29c079b58fe9c79.tar.bz2 |
[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
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r-- | clang/unittests/libclang/LibclangTest.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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"; |