xref: /llvm-project/llvm/unittests/Target/PowerPC/AIXRelocModelTest.cpp (revision 0a1aa6cda2758b0926a95f87d39ffefb1cb90200)
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 
7 using namespace llvm;
8 
9 namespace {
10 
11 class AIXRelocModelTest : public ::testing::Test {
12 protected:
SetUpTestCase()13   static void SetUpTestCase() {
14     LLVMInitializePowerPCTargetInfo();
15     LLVMInitializePowerPCTarget();
16     LLVMInitializePowerPCTargetMC();
17   }
18 };
19 
TEST_F(AIXRelocModelTest,DefalutToPIC)20 TEST_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 its
28   // relocation model unset.
29   std::unique_ptr<TargetMachine> Target(TheTarget->createTargetMachine(
30       /*TT*/ TheTriple.getTriple(), /*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 namespace
40