LibclangCrashTest.cpp
1.31 KB
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
//===- unittests/libclang/LibclangCrashTest.cpp --- libclang tests --------===//
//
// 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 "../TestUtils.h"
#include "clang-c/FatalErrorHandler.h"
#include "gtest/gtest.h"
#include <string>
TEST_F(LibclangParseTest, InstallAbortingLLVMFatalErrorHandler) {
clang_toggleCrashRecovery(0);
clang_install_aborting_llvm_fatal_error_handler();
std::string Main = "main.h";
WriteFile(Main, "#pragma clang __debug llvm_fatal_error");
EXPECT_DEATH(clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
nullptr, 0, TUFlags),
"");
}
TEST_F(LibclangParseTest, UninstallAbortingLLVMFatalErrorHandler) {
clang_toggleCrashRecovery(0);
clang_install_aborting_llvm_fatal_error_handler();
clang_uninstall_llvm_fatal_error_handler();
std::string Main = "main.h";
WriteFile(Main, "#pragma clang __debug llvm_fatal_error");
EXPECT_DEATH(clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
nullptr, 0, TUFlags),
"ERROR");
}