summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2016-03-23 21:49:31 +0000
committerPete Cooper <peter_cooper@apple.com>2016-03-23 21:49:31 +0000
commitb08d9060b77ee35d278397dfca54a72a86c3a9bb (patch)
tree6004f37b8f47d10989b721e7ff9078aa0b98463b /llvm/unittests/ADT/StringRefTest.cpp
parentf43c2a0b4967626c7255940a7317ec4c8c9e9319 (diff)
downloadbcm5719-llvm-b08d9060b77ee35d278397dfca54a72a86c3a9bb.tar.gz
bcm5719-llvm-b08d9060b77ee35d278397dfca54a72a86c3a9bb.zip
StringRef::copy shouldn't allocate anything for length 0 strings.
The BumpPtrAllocator currently doesn't handle zero length allocations well. The discussion for how to fix that is ongoing. However, there's no need for StringRef::copy to actually allocate anything here anyway, so just return StringRef() when we get a zero length copy. Reviewed by David Blaikie llvm-svn: 264201
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index 6354026d7ae..66e5944b56e 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -589,6 +589,15 @@ TEST(StringRefTest, joinStrings) {
TEST(StringRefTest, AllocatorCopy) {
BumpPtrAllocator Alloc;
+ // First test empty strings. We don't want these to allocate anything on the
+ // allocator.
+ StringRef StrEmpty = "";
+ StringRef StrEmptyc = StrEmpty.copy(Alloc);
+ EXPECT_TRUE(StrEmpty.equals(StrEmptyc));
+ EXPECT_EQ(StrEmptyc.data(), nullptr);
+ EXPECT_EQ(StrEmptyc.size(), 0u);
+ EXPECT_EQ(Alloc.getTotalMemory(), 0u);
+
StringRef Str1 = "hello";
StringRef Str2 = "bye";
StringRef Str1c = Str1.copy(Alloc);
OpenPOWER on IntegriCloud