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 89 : 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 10 : void __attribute__ ((noinline)) set_one(unsigned char* ptr) 13 : { 14 10 : *ptr = 1; 15 10 : } 16 : 17 5 : int __attribute__ ((noinline)) check_zero(unsigned char const* in, unsigned int len) 18 : { 19 15 : for (unsigned int i = 0; i < len; ++i) { 20 10 : if (in[i] != 0) return 0; 21 : } 22 5 : return 1; 23 5 : } 24 : 25 10 : void set_one_on_stack() { 26 10 : unsigned char buf[1]; 27 10 : set_one(buf); 28 10 : } 29 : 30 95 : BOOST_AUTO_TEST_CASE(gccbug_90348) { 31 : // Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 32 6 : for (int i = 0; i <= 4; ++i) { 33 5 : unsigned char in[4]; 34 15 : for (int j = 0; j < i; ++j) { 35 10 : in[j] = 0; 36 10 : set_one_on_stack(); // Apparently modifies in[0] 37 : } 38 5 : BOOST_CHECK(check_zero(in, i)); 39 5 : } 40 1 : } 41 : #endif 42 : 43 89 : BOOST_AUTO_TEST_SUITE_END()