File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ BITCOIN_TESTS =\
97
97
test/bswap_tests.cpp \
98
98
test/checkqueue_tests.cpp \
99
99
test/coins_tests.cpp \
100
+ test/compilerbug_tests.cpp \
100
101
test/compress_tests.cpp \
101
102
test/crypto_tests.cpp \
102
103
test/cuckoocache_tests.cpp \
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2019 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 < test/setup_common.h>
6
+ #include < boost/test/unit_test.hpp>
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
+ {
14
+ *ptr = 1 ;
15
+ }
16
+
17
+ int __attribute__ ((noinline)) check_zero(unsigned char const * in, unsigned int len)
18
+ {
19
+ for (unsigned int i = 0 ; i < len; ++i) {
20
+ if (in[i] != 0 ) return 0 ;
21
+ }
22
+ return 1 ;
23
+ }
24
+
25
+ void set_one_on_stack () {
26
+ unsigned char buf[1 ];
27
+ set_one (buf);
28
+ }
29
+
30
+ BOOST_AUTO_TEST_CASE (gccbug_90348) {
31
+ // Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348
32
+ for (int i = 0 ; i <= 4 ; ++i) {
33
+ unsigned char in[4 ];
34
+ for (int j = 0 ; j < i; ++j) {
35
+ in[j] = 0 ;
36
+ set_one_on_stack (); // Apparently modifies in[0]
37
+ }
38
+ BOOST_CHECK (check_zero (in, i));
39
+ }
40
+ }
41
+ #endif
42
+
43
+ BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments