summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/FormatVariadicTest.cpp
diff options
context:
space:
mode:
authorBenoit Belley <benoit.belley@autodesk.com>2017-08-09 13:47:01 +0000
committerBenoit Belley <benoit.belley@autodesk.com>2017-08-09 13:47:01 +0000
commitd9017cc65e6f765072b11eb11828714792ae16ff (patch)
treeb4a3aeaeca39ecd1a27d0d476c8f75016c5b563c /llvm/unittests/Support/FormatVariadicTest.cpp
parent6110d3ad0095f81823e74d4f47a1efa3e095a406 (diff)
downloadbcm5719-llvm-d9017cc65e6f765072b11eb11828714792ae16ff.tar.gz
bcm5719-llvm-d9017cc65e6f765072b11eb11828714792ae16ff.zip
[Support] PR33388 - Fix formatv_object move constructor
formatv_object currently uses the implicitly defined move constructor, but it is buggy. In typical use-cases, the problem doesn't show-up because all calls to the move constructor are elided. Thus, the buggy constructors are never invoked. The issue especially shows-up when code is compiled using the -fno-elide-constructors compiler flag. For instance, this is useful when attempting to collect accurate code coverage statistics. The exact issue is the following: The Parameters data member is correctly moved, thus making the parameters occupy a new memory location in the target object. Unfortunately, the default copying of the Adapters blindly copies the vector of pointers, leaving each of these pointers referencing the parameters in the original object instead of the copied one. These pointers quickly become dangling when the original object is deleted. This quickly leads to crashes. The solution is to update the Adapters pointers when performing a move. The copy constructor isn't useful for format objects and can thus be deleted. This resolves PR33388. Differential Revision: https://reviews.llvm.org/D34463 llvm-svn: 310475
Diffstat (limited to 'llvm/unittests/Support/FormatVariadicTest.cpp')
-rw-r--r--llvm/unittests/Support/FormatVariadicTest.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index 5387a8ae499..bfbe556b31a 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -553,6 +553,12 @@ TEST(FormatVariadicTest, Adapter) {
formatv("{0,=34:X-}", fmt_repeat(fmt_pad(N, 1, 3), 5)).str());
}
+TEST(FormatVariadicTest, MoveConstructor) {
+ auto fmt = formatv("{0} {1}", 1, 2);
+ auto fmt2 = std::move(fmt);
+ std::string S = fmt2;
+ EXPECT_EQ("1 2", S);
+}
TEST(FormatVariadicTest, ImplicitConversions) {
std::string S = formatv("{0} {1}", 1, 2);
EXPECT_EQ("1 2", S);
OpenPOWER on IntegriCloud