1//===- unittests/libclang/LibclangCrashTest.cpp --- libclang tests --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "../TestUtils.h"
10#include "clang-c/FatalErrorHandler.h"
11#include "gtest/gtest.h"
12#include <string>
13
14TEST_F(LibclangParseTest, InstallAbortingLLVMFatalErrorHandler) {
15 clang_toggleCrashRecovery(isEnabled: 0);
16 clang_install_aborting_llvm_fatal_error_handler();
17
18 std::string Main = "main.h";
19 WriteFile(Filename&: Main, Contents: "#pragma clang __debug llvm_fatal_error");
20
21 EXPECT_DEATH(clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
22 nullptr, 0, TUFlags),
23 "");
24}
25
26TEST_F(LibclangParseTest, UninstallAbortingLLVMFatalErrorHandler) {
27 clang_toggleCrashRecovery(isEnabled: 0);
28 clang_install_aborting_llvm_fatal_error_handler();
29 clang_uninstall_llvm_fatal_error_handler();
30
31 std::string Main = "main.h";
32 WriteFile(Filename&: Main, Contents: "#pragma clang __debug llvm_fatal_error");
33
34 EXPECT_DEATH(clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
35 nullptr, 0, TUFlags),
36 "ERROR");
37}
38

source code of clang/unittests/libclang/CrashTests/LibclangCrashTest.cpp