row_cache_alloc_stress_test: Make sure GCC can't delete a new

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 <espindola@scylladb.com>
Message-Id: <20200424201531.225807-1-espindola@scylladb.com>
This commit is contained in:
Rafael Ávila de Espíndola
2020-04-24 13:15:31 -07:00
committed by Avi Kivity
parent 543a9ebd9b
commit 0d89bbd57f

View File

@@ -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