Add a header-only implementation of Briggs & Torczon's fast small integer set data structure to flang/include/flang/Common, and use it in the runtime to manage a pool of Fortran unit numbers with recycling. This replaces the bit set previously used for that purpose. The set is initialized on demand with the negations of all the NEWUNIT= unit numbers that can be returned to any kind of integer variable. For programs that require more concurrently open NEWUNIT= unit numbers than the pool can hold, they are now allocated with a non-recycling counter. This allows as many open units as the operating system provides. Many of the top-line comments in flang/unittests/Runtime had the wrong path name. I noticed this while adding a unit test for the fast integer set data structure, and cleaned them up. Differential Revision: https://reviews.llvm.org/D120685
38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#include "CrashHandlerFixture.h"
|
|
#include "../../runtime/terminator.h"
|
|
#include <cstdarg>
|
|
#include <cstdlib>
|
|
|
|
// Replaces Fortran runtime's crash handler so we can verify the crash message
|
|
[[noreturn]] static void CatchCrash(
|
|
const char *sourceFile, int sourceLine, const char *message, va_list &ap) {
|
|
char buffer[1000];
|
|
std::vsnprintf(buffer, sizeof buffer, message, ap);
|
|
va_end(ap);
|
|
llvm::errs()
|
|
<< "Test "
|
|
<< ::testing::UnitTest::GetInstance()->current_test_info()->name()
|
|
<< " crashed in file "
|
|
<< (sourceFile ? sourceFile : "unknown source file") << '(' << sourceLine
|
|
<< "): " << buffer << '\n';
|
|
std::exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// Register the crash handler above when creating each unit test in this suite
|
|
void CrashHandlerFixture::SetUp() {
|
|
static bool isCrashHanlderRegistered{false};
|
|
|
|
if (!isCrashHanlderRegistered) {
|
|
Fortran::runtime::Terminator::RegisterCrashHandler(CatchCrash);
|
|
}
|
|
|
|
isCrashHanlderRegistered = true;
|
|
}
|