brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 03e81ae Raw
40 lines · cpp
1#include "llvm/MC/TargetRegistry.h"2#include "llvm/Support/TargetSelect.h"3#include "llvm/Target/TargetMachine.h"4#include "llvm/TargetParser/Triple.h"5#include "gtest/gtest.h"6 7using namespace llvm;8 9namespace {10 11class AIXRelocModelTest : public ::testing::Test {12protected:13  static void SetUpTestCase() {14    LLVMInitializePowerPCTargetInfo();15    LLVMInitializePowerPCTarget();16    LLVMInitializePowerPCTargetMC();17  }18};19 20TEST_F(AIXRelocModelTest, DefalutToPIC) {21  Triple TheTriple(/*ArchStr*/ "powerpc", /*VendorStr*/ "", /*OSStr*/ "aix");22  std::string Error;23  const Target *TheTarget = TargetRegistry::lookupTarget("", TheTriple, Error);24  ASSERT_TRUE(TheTarget) << Error;25 26  TargetOptions Options;27  // Create a TargetMachine for powerpc--aix target, and deliberately leave its28  // relocation model unset.29  std::unique_ptr<TargetMachine> Target(TheTarget->createTargetMachine(30      /*TT*/ TheTriple, /*CPU*/ "", /*Features*/ "",31      /*Options*/ Options, /*RM*/ std::nullopt, /*CM*/ std::nullopt,32      /*OL*/ CodeGenOptLevel::Default));33  ASSERT_TRUE(Target) << "Could not allocate target machine!";34 35  // The relocation model on AIX should be forced to PIC regardless.36  EXPECT_TRUE(Target->getRelocationModel() == Reloc::PIC_);37}38 39} // end of anonymous namespace40