Skip to content

Commit d936cf9

Browse files
committed
Merge #15985: Add test for GCC bug 90348
58e291c Add test for GCC bug 90348 (Pieter Wuille) Pull request description: This adds a test for GCC bug 90348 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348), using a test case extracted from our own `sha256d64` test in crypto_tests.cpp, which was failing on some platforms. This is based on top of #15983 to make sure the bug doesn't trigger (it does in some Travis configurations without it). ACKs for commit 58e291: Tree-SHA512: 4dc9084e92dd143a53930e42bb68e33d922a2a2b891406b259d3a0bed4511dcc49e7447a7a8e4eb793a26e3eacb188ca293b71e0e061f9b3230f8e7fcfd29525
2 parents 52ec4c6 + 58e291c commit d936cf9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ BITCOIN_TESTS =\
9797
test/bswap_tests.cpp \
9898
test/checkqueue_tests.cpp \
9999
test/coins_tests.cpp \
100+
test/compilerbug_tests.cpp \
100101
test/compress_tests.cpp \
101102
test/crypto_tests.cpp \
102103
test/cuckoocache_tests.cpp \

src/test/compilerbug_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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()

0 commit comments

Comments
 (0)