Skip to content

Commit 8fbdf93

Browse files
committed
Sanity check to detect LLVM bug 96267
1 parent 1b37568 commit 8fbdf93

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/kernel/checks.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@
1313

1414
namespace kernel {
1515

16+
bool Clang_IndVarSimplify_Bug_SanityCheck() {
17+
// See https://github.com/llvm/llvm-project/issues/96267
18+
const char s[] = {0, 0x75};
19+
signed int last = 0xff;
20+
for (const char *it = s; it < &s[2]; ++it) {
21+
if (*it <= 0x4e) {
22+
} else if (*it == 0x75 && last <= 0x4e) {
23+
return true;
24+
}
25+
last = *it;
26+
}
27+
return false;
28+
}
29+
1630
util::Result<void> SanityChecks(const Context&)
1731
{
1832
if (auto result{dbwrapper_SanityCheck()}; !result) {
1933
return util::Error{util::ErrorString(result) + Untranslated("\nDatabase sanity check failure. Aborting.")};
2034
}
2135

36+
if (!Clang_IndVarSimplify_Bug_SanityCheck()) {
37+
return util::Error{Untranslated("Compiler optimization sanity check failure. Aborting.")};
38+
}
39+
2240
if (!Random_SanityCheck()) {
2341
return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
2442
}

src/kernel/checks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace kernel {
1111

1212
struct Context;
1313

14+
[[nodiscard]] bool Clang_IndVarSimplify_Bug_SanityCheck();
15+
1416
/**
1517
* Ensure a usable environment with all necessary library support.
1618
*/

src/test/sanity_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <dbwrapper.h>
6+
#include <kernel/checks.h>
67
#include <key.h>
78
#include <test/util/setup_common.h>
89

@@ -13,6 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(sanity_tests, BasicTestingSetup)
1314
BOOST_AUTO_TEST_CASE(basic_sanity)
1415
{
1516
BOOST_CHECK_MESSAGE(dbwrapper_SanityCheck(), "dbwrapper sanity test");
17+
BOOST_CHECK_MESSAGE(kernel::Clang_IndVarSimplify_Bug_SanityCheck() == true, "Clang IndVarSimplify bug sanity test");
1618
BOOST_CHECK_MESSAGE(ECC_InitSanityCheck() == true, "secp256k1 sanity test");
1719
}
1820

0 commit comments

Comments
 (0)