LCOV - code coverage report
Current view: top level - src/test - compilerbug_tests.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 23 23 100.0 %
Date: 2026-06-25 07:23:51 Functions: 9 9 100.0 %

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

Generated by: LCOV version 1.16