Branch data Line data Source code
# 1 : : // Copyright (c) 2019-2020 The Bitcoin Core developers # 2 : : // Distributed under the MIT software license, see the accompanying # 3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php. # 4 : : # 5 : : #include <boost/test/unit_test.hpp> # 6 : : #include <test/util/setup_common.h> # 7 : : # 8 : : BOOST_FIXTURE_TEST_SUITE(compilerbug_tests, BasicTestingSetup) # 9 : : # 10 : : #if defined(__GNUC__) # 11 : : // This block will also be built under clang, which is fine (as it supports noinline) # 12 : : void __attribute__ ((noinline)) set_one(unsigned char* ptr) # 13 : 20 : { # 14 : 20 : *ptr = 1; # 15 : 20 : } # 16 : : # 17 : : int __attribute__ ((noinline)) check_zero(unsigned char const* in, unsigned int len) # 18 : 10 : { # 19 [ + + ]: 30 : for (unsigned int i = 0; i < len; ++i) { # 20 [ - + ]: 20 : if (in[i] != 0) return 0; # 21 : 20 : } # 22 : 10 : return 1; # 23 : 10 : } # 24 : : # 25 : 20 : void set_one_on_stack() { # 26 : 20 : unsigned char buf[1]; # 27 : 20 : set_one(buf); # 28 : 20 : } # 29 : : # 30 : 2 : BOOST_AUTO_TEST_CASE(gccbug_90348) { # 31 : : // Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 # 32 [ + + ]: 12 : for (int i = 0; i <= 4; ++i) { # 33 : 10 : unsigned char in[4]; # 34 [ + + ]: 30 : for (int j = 0; j < i; ++j) { # 35 : 20 : in[j] = 0; # 36 : 20 : set_one_on_stack(); // Apparently modifies in[0] # 37 : 20 : } # 38 : 10 : BOOST_CHECK(check_zero(in, i)); # 39 : 10 : } # 40 : 2 : } # 41 : : #endif # 42 : : # 43 : : BOOST_AUTO_TEST_SUITE_END()