diff --git a/llvm/lib/CAS/OnDiskCAS.cpp b/llvm/lib/CAS/OnDiskCAS.cpp index cb06677eab9d6..dab6e6d8c98bd 100644 --- a/llvm/lib/CAS/OnDiskCAS.cpp +++ b/llvm/lib/CAS/OnDiskCAS.cpp @@ -765,7 +765,7 @@ class OnDiskCAS : public BuiltinCAS { static constexpr StringLiteral DataPoolFile = "data"; static constexpr StringLiteral ActionCacheFile = "actions"; - static constexpr StringLiteral FilePrefix = "v3."; + static constexpr StringLiteral FilePrefix = "v4."; static constexpr StringLiteral FileSuffixData = ".data"; static constexpr StringLiteral FileSuffixLeaf = ".leaf"; static constexpr StringLiteral FileSuffixLeaf0 = ".leaf+0"; @@ -1903,7 +1903,7 @@ Expected OnDiskCAS::storeNodeImpl(ArrayRef ComputedHash, } // Big leaf nodes. - if (Data.size() > TrieRecord::MaxEmbeddedSize) + if (Refs.empty() && Data.size() > TrieRecord::MaxEmbeddedSize) return createStandaloneLeaf(I, Data); // TODO: Check whether it's worth checking the index for an already existing diff --git a/llvm/unittests/CAS/CASDBTest.cpp b/llvm/unittests/CAS/CASDBTest.cpp index 0901569ba0d49..f6abdc4860ad9 100644 --- a/llvm/unittests/CAS/CASDBTest.cpp +++ b/llvm/unittests/CAS/CASDBTest.cpp @@ -400,15 +400,21 @@ TEST_P(CASDBTest, NodesBig) { if (Storage.size() < SizeE) Storage.resize(SizeE, '\01'); + SmallVector CreatedNodes; // Avoid checking every size because this is an expensive test. Just check - // for data that is 8B-word-aligned, and one less. + // for data that is 8B-word-aligned, and one less. Also appending the created + // nodes as the references in the next block to check references are created + // correctly. for (size_t Size = SizeB; Size < SizeE; Size += WordSize) { for (bool IsAligned : {false, true}) { StringRef Data(Storage.data(), Size - (IsAligned ? 0 : 1)); Optional Node; - ASSERT_THAT_ERROR(CAS->createNode(None, Data).moveInto(Node), Succeeded()); + ASSERT_THAT_ERROR(CAS->createNode(CreatedNodes, Data).moveInto(Node), + Succeeded()); ASSERT_EQ(Data, Node->getData()); ASSERT_EQ(0, Node->getData().end()[0]); + ASSERT_EQ(Node->getNumReferences(), CreatedNodes.size()); + CreatedNodes.emplace_back(Node->getID()); } } }