[NFC] Skip PassBuilderCTests if no default triple

This fixes the unit tests so that it is skipped if there is no default
target triple set. Unset default target triple is a supported build
configuration for LLVM.
This commit is contained in:
Chris Bieneman
2022-01-31 15:44:55 -06:00
parent d46305e22d
commit 2d66ed370a

View File

@@ -10,13 +10,18 @@
#include "llvm-c/Transforms/PassBuilder.h"
#include "llvm-c/Types.h"
#include "gtest/gtest.h"
#include <string.h>
using namespace llvm;
class PassBuilderCTest : public testing::Test {
void SetUp() override {
LLVMInitializeAllTargetInfos();
char *Triple = LLVMGetDefaultTargetTriple();
if (strlen(Triple) == 0) {
GTEST_SKIP();
return;
}
LLVMInitializeAllTargetInfos();
char *Err;
LLVMTargetRef Target;
if (LLVMGetTargetFromTriple(Triple, &Target, &Err)) {
@@ -32,6 +37,9 @@ class PassBuilderCTest : public testing::Test {
}
void TearDown() override {
char *Triple = LLVMGetDefaultTargetTriple();
if (strlen(Triple) == 0)
return; // Skipped, so nothing to tear down
LLVMDisposeTargetMachine(TM);
LLVMDisposeModule(Module);
LLVMContextDispose(Context);