forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compilerbug_tests.cpp
42 lines (35 loc) · 1.1 KB
/
compilerbug_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(compilerbug_tests)
#if defined(__GNUC__)
// This block will also be built under clang, which is fine (as it supports noinline)
void __attribute__ ((noinline)) set_one(unsigned char* ptr)
{
*ptr = 1;
}
int __attribute__ ((noinline)) check_zero(unsigned char const* in, unsigned int len)
{
for (unsigned int i = 0; i < len; ++i) {
if (in[i] != 0) return 0;
}
return 1;
}
void set_one_on_stack() {
unsigned char buf[1];
set_one(buf);
}
BOOST_AUTO_TEST_CASE(gccbug_90348) {
// Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348
for (int i = 0; i <= 4; ++i) {
unsigned char in[4];
for (int j = 0; j < i; ++j) {
in[j] = 0;
set_one_on_stack(); // Apparently modifies in[0]
}
BOOST_CHECK(check_zero(in, i));
}
}
#endif
BOOST_AUTO_TEST_SUITE_END()