llvm-project/flang/unittests/Runtime/CrashHandlerFixture.cpp
David Spickett ffc67bb360 Revert "[Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration"
This reverts commit 6403287eff71a3d6f6c862346d6ed3f0f000eb70.

This is failing on all but 1 of Linaro's flang builders.
CMake Error at /home/tcwg-buildbot/worker/clang-aarch64-full-2stage/llvm/flang-rt/unittests/CMakeLists.txt:37 (message):
  Target llvm_gtest not found.
2023-10-02 09:02:05 +00:00

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;
}