| 1 |
#include "llvm/ADT/Triple.h" |
| 2 |
#include "llvm/MC/TargetRegistry.h" |
| 3 |
#include "llvm/Support/TargetSelect.h" |
| 4 |
#include "llvm/Target/TargetMachine.h" |
| 5 |
#include "gtest/gtest.h" |
| 6 |
|
| 7 |
using namespace llvm; |
| 8 |
|
| 9 |
namespace { |
| 10 |
|
| 11 |
class AIXRelocModelTest : public ::testing::Test { |
| 12 |
protected: |
| 13 |
static void SetUpTestCase() { |
| 14 |
LLVMInitializePowerPCTargetInfo(); |
| 15 |
LLVMInitializePowerPCTarget(); |
| 16 |
LLVMInitializePowerPCTargetMC(); |
| 17 |
} |
| 18 |
}; |
| 19 |
|
| 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*/ CodeGenOpt::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 |