From 0d89bbd57f2889e8e50b897ac4f2995b9d45e697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 24 Apr 2020 13:15:31 -0700 Subject: [PATCH] row_cache_alloc_stress_test: Make sure GCC can't delete a new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to test that a std::bad_alloc is thrown, but GCC 10 has a new optimization (-fallocation-dce) that removes dead allocations. This patch assigns the value returned by new to a global so that GCC cannot delete it. With this all tests in a dev build pass with GCC 10. Signed-off-by: Rafael Ávila de Espíndola Message-Id: <20200424201531.225807-1-espindola@scylladb.com> --- test/unit/row_cache_alloc_stress_test.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/row_cache_alloc_stress_test.cc b/test/unit/row_cache_alloc_stress_test.cc index 37dd4d5655..bbbc78512c 100644 --- a/test/unit/row_cache_alloc_stress_test.cc +++ b/test/unit/row_cache_alloc_stress_test.cc @@ -43,6 +43,8 @@ clustering_key new_ckey(schema_ptr s) { return clustering_key::from_single_value(*s, to_bytes(format("ckey{:d}", next++))); } +void *leak; + int main(int argc, char** argv) { namespace bpo = boost::program_options; app_template app; @@ -242,7 +244,9 @@ int main(int argc, char** argv) { auto reader = cache.make_reader(s, range); assert(!reader(db::no_timeout).get0()); auto evicted_from_cache = logalloc::segment_size + large_cell_size; - new char[evicted_from_cache + logalloc::segment_size]; + // GCC's -fallocation-dce can remove dead calls to new and malloc, so + // assign the result to a global variable to disable it. + leak = new char[evicted_from_cache + logalloc::segment_size]; assert(false); // The test is not invoking the case which it's supposed to test } catch (const std::bad_alloc&) { // expected