compilerbug_tests.cpp
1 // Copyright (c) 2019-2021 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 7 BOOST_AUTO_TEST_SUITE(compilerbug_tests) 8 9 #if defined(__GNUC__) 10 // This block will also be built under clang, which is fine (as it supports noinline) 11 void __attribute__ ((noinline)) set_one(unsigned char* ptr) 12 { 13 *ptr = 1; 14 } 15 16 int __attribute__ ((noinline)) check_zero(unsigned char const* in, unsigned int len) 17 { 18 for (unsigned int i = 0; i < len; ++i) { 19 if (in[i] != 0) return 0; 20 } 21 return 1; 22 } 23 24 void set_one_on_stack() { 25 unsigned char buf[1]; 26 set_one(buf); 27 } 28 29 BOOST_AUTO_TEST_CASE(gccbug_90348) { 30 // Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 31 for (int i = 0; i <= 4; ++i) { 32 unsigned char in[4]; 33 for (int j = 0; j < i; ++j) { 34 in[j] = 0; 35 set_one_on_stack(); // Apparently modifies in[0] 36 } 37 BOOST_CHECK(check_zero(in, i)); 38 } 39 } 40 #endif 41 42 BOOST_AUTO_TEST_SUITE_END()