aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/IR
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR')
-rw-r--r--unittests/IR/ConstantRangeTest.cpp65
-rw-r--r--unittests/IR/ConstantsTest.cpp4
-rw-r--r--unittests/IR/DebugInfoTest.cpp20
-rw-r--r--unittests/IR/IRBuilderTest.cpp6
-rw-r--r--unittests/IR/InstructionsTest.cpp30
-rw-r--r--unittests/IR/LegacyPassManagerTest.cpp10
-rw-r--r--unittests/IR/MetadataTest.cpp177
7 files changed, 266 insertions, 46 deletions
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp
index fa03302..de4eec4 100644
--- a/unittests/IR/ConstantRangeTest.cpp
+++ b/unittests/IR/ConstantRangeTest.cpp
@@ -400,6 +400,13 @@ TEST_F(ConstantRangeTest, Multiply) {
EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))),
ConstantRange(4, /*isFullSet=*/true));
+
+ EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 0)).multiply(
+ ConstantRange(APInt(8, 252), APInt(8, 4))),
+ ConstantRange(APInt(8, 250), APInt(8, 9)));
+ EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 255)).multiply(
+ ConstantRange(APInt(8, 2), APInt(8, 4))),
+ ConstantRange(APInt(8, 250), APInt(8, 253)));
}
TEST_F(ConstantRangeTest, UMax) {
@@ -502,11 +509,63 @@ TEST_F(ConstantRangeTest, Lshr) {
EXPECT_EQ(Wrap.lshr(Wrap), Full);
}
-TEST(ConstantRange, MakeICmpRegion) {
+TEST(ConstantRange, MakeAllowedICmpRegion) {
// PR8250
ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32));
- EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT,
- SMax).isEmptySet());
+ EXPECT_TRUE(ConstantRange::makeAllowedICmpRegion(ICmpInst::ICMP_SGT, SMax)
+ .isEmptySet());
+}
+
+TEST(ConstantRange, MakeSatisfyingICmpRegion) {
+ ConstantRange LowHalf(APInt(8, 0), APInt(8, 128));
+ ConstantRange HighHalf(APInt(8, 128), APInt(8, 0));
+ ConstantRange EmptySet(8, /* isFullSet = */ false);
+
+ EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, LowHalf),
+ HighHalf);
+
+ EXPECT_EQ(
+ ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, HighHalf),
+ LowHalf);
+
+ EXPECT_TRUE(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_EQ,
+ HighHalf).isEmptySet());
+
+ ConstantRange UnsignedSample(APInt(8, 5), APInt(8, 200));
+
+ EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULT,
+ UnsignedSample),
+ ConstantRange(APInt(8, 0), APInt(8, 5)));
+
+ EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULE,
+ UnsignedSample),
+ ConstantRange(APInt(8, 0), APInt(8, 6)));
+
+ EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGT,
+ UnsignedSample),
+ ConstantRange(APInt(8, 200), APInt(8, 0)));
+
+ EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGE,
+ UnsignedSample),
+ ConstantRange(APInt(8, 199), APInt(8, 0)));
+
+ ConstantRange SignedSample(APInt(8, -5), APInt(8, 5));
+
+ EXPECT_EQ(
+ ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLT, SignedSample),
+ ConstantRange(APInt(8, -128), APInt(8, -5)));
+
+ EXPECT_EQ(
+ ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLE, SignedSample),
+ ConstantRange(APInt(8, -128), APInt(8, -4)));
+
+ EXPECT_EQ(
+ ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGT, SignedSample),
+ ConstantRange(APInt(8, 5), APInt(8, -128)));
+
+ EXPECT_EQ(
+ ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGE, SignedSample),
+ ConstantRange(APInt(8, 4), APInt(8, -128)));
}
} // anonymous namespace
diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp
index 5d271e2..0e040bc 100644
--- a/unittests/IR/ConstantsTest.cpp
+++ b/unittests/IR/ConstantsTest.cpp
@@ -248,9 +248,9 @@ TEST(ConstantsTest, AsInstructionsTest) {
// FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP,
// not a normal one!
//CHECK(ConstantExpr::getGetElementPtr(Global, V, false),
- // "getelementptr i32** @dummy, i32 1");
+ // "getelementptr i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V),
- "getelementptr inbounds i32** @dummy, i32 1");
+ "getelementptr inbounds i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> "
P6STR ", i32 1");
diff --git a/unittests/IR/DebugInfoTest.cpp b/unittests/IR/DebugInfoTest.cpp
index 3c6c786..a957b99 100644
--- a/unittests/IR/DebugInfoTest.cpp
+++ b/unittests/IR/DebugInfoTest.cpp
@@ -117,17 +117,17 @@ TEST(DIDescriptorTest, splitFlags) {
{ \
SmallVector<unsigned, 8> V; \
EXPECT_EQ(REMAINDER, DIDescriptor::splitFlags(FLAGS, V)); \
- EXPECT_TRUE(makeArrayRef(V).equals VECTOR); \
+ EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
}
- CHECK_SPLIT(DIDescriptor::FlagPublic, (DIDescriptor::FlagPublic), 0u);
- CHECK_SPLIT(DIDescriptor::FlagProtected, (DIDescriptor::FlagProtected), 0u);
- CHECK_SPLIT(DIDescriptor::FlagPrivate, (DIDescriptor::FlagPrivate), 0u);
- CHECK_SPLIT(DIDescriptor::FlagVector, (DIDescriptor::FlagVector), 0u);
- CHECK_SPLIT(DIDescriptor::FlagRValueReference, (DIDescriptor::FlagRValueReference), 0u);
- CHECK_SPLIT(DIDescriptor::FlagFwdDecl | DIDescriptor::FlagVector,
- (DIDescriptor::FlagFwdDecl, DIDescriptor::FlagVector), 0u);
- CHECK_SPLIT(0x100000u, (), 0x100000u);
- CHECK_SPLIT(0x100000u | DIDescriptor::FlagVector, (DIDescriptor::FlagVector),
+ CHECK_SPLIT(DIDescriptor::FlagPublic, {DIDescriptor::FlagPublic}, 0u);
+ CHECK_SPLIT(DIDescriptor::FlagProtected, {DIDescriptor::FlagProtected}, 0u);
+ CHECK_SPLIT(DIDescriptor::FlagPrivate, {DIDescriptor::FlagPrivate}, 0u);
+ CHECK_SPLIT(DIDescriptor::FlagVector, {DIDescriptor::FlagVector}, 0u);
+ CHECK_SPLIT(DIDescriptor::FlagRValueReference, {DIDescriptor::FlagRValueReference}, 0u);
+ unsigned Flags[] = {DIDescriptor::FlagFwdDecl, DIDescriptor::FlagVector};
+ CHECK_SPLIT(DIDescriptor::FlagFwdDecl | DIDescriptor::FlagVector, Flags, 0u);
+ CHECK_SPLIT(0x100000u, {}, 0x100000u);
+ CHECK_SPLIT(0x100000u | DIDescriptor::FlagVector, {DIDescriptor::FlagVector},
0x100000u);
#undef CHECK_SPLIT
}
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp
index 08a729a..ca378a3 100644
--- a/unittests/IR/IRBuilderTest.cpp
+++ b/unittests/IR/IRBuilderTest.cpp
@@ -111,9 +111,9 @@ TEST_F(IRBuilderTest, LandingPadName) {
TEST_F(IRBuilderTest, DataLayout) {
std::unique_ptr<Module> M(new Module("test", Ctx));
M->setDataLayout("e-n32");
- EXPECT_TRUE(M->getDataLayout()->isLegalInteger(32));
+ EXPECT_TRUE(M->getDataLayout().isLegalInteger(32));
M->setDataLayout("e");
- EXPECT_FALSE(M->getDataLayout()->isLegalInteger(32));
+ EXPECT_FALSE(M->getDataLayout().isLegalInteger(32));
}
TEST_F(IRBuilderTest, GetIntTy) {
@@ -122,7 +122,7 @@ TEST_F(IRBuilderTest, GetIntTy) {
EXPECT_EQ(Ty1, IntegerType::get(Ctx, 1));
DataLayout* DL = new DataLayout(M.get());
- IntegerType *IntPtrTy = Builder.getIntPtrTy(DL);
+ IntegerType *IntPtrTy = Builder.getIntPtrTy(*DL);
unsigned IntPtrBitSize = DL->getPointerSizeInBits(0);
EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
delete DL;
diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp
index 7ec9b62..3ca3ad2 100644
--- a/unittests/IR/InstructionsTest.cpp
+++ b/unittests/IR/InstructionsTest.cpp
@@ -291,8 +291,10 @@ TEST(InstructionsTest, VectorGep) {
LLVMContext &C(getGlobalContext());
// Type Definitions
- PointerType *Ptri8Ty = PointerType::get(IntegerType::get(C, 8), 0);
- PointerType *Ptri32Ty = PointerType::get(IntegerType::get(C, 32), 0);
+ Type *I8Ty = IntegerType::get(C, 8);
+ Type *I32Ty = IntegerType::get(C, 32);
+ PointerType *Ptri8Ty = PointerType::get(I8Ty, 0);
+ PointerType *Ptri32Ty = PointerType::get(I32Ty, 0);
VectorType *V2xi8PTy = VectorType::get(Ptri8Ty, 2);
VectorType *V2xi32PTy = VectorType::get(Ptri32Ty, 2);
@@ -318,10 +320,10 @@ TEST(InstructionsTest, VectorGep) {
ICmpInst *ICmp2 = new ICmpInst(*BB0, ICmpInst::ICMP_SGE, PtrVecA, PtrVecB);
EXPECT_NE(ICmp0, ICmp2); // suppress warning.
- GetElementPtrInst *Gep0 = GetElementPtrInst::Create(PtrVecA, C2xi32a);
- GetElementPtrInst *Gep1 = GetElementPtrInst::Create(PtrVecA, C2xi32b);
- GetElementPtrInst *Gep2 = GetElementPtrInst::Create(PtrVecB, C2xi32a);
- GetElementPtrInst *Gep3 = GetElementPtrInst::Create(PtrVecB, C2xi32b);
+ GetElementPtrInst *Gep0 = GetElementPtrInst::Create(I32Ty, PtrVecA, C2xi32a);
+ GetElementPtrInst *Gep1 = GetElementPtrInst::Create(I32Ty, PtrVecA, C2xi32b);
+ GetElementPtrInst *Gep2 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32a);
+ GetElementPtrInst *Gep3 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32b);
CastInst *BTC0 = new BitCastInst(Gep0, V2xi8PTy);
CastInst *BTC1 = new BitCastInst(Gep1, V2xi8PTy);
@@ -343,16 +345,16 @@ TEST(InstructionsTest, VectorGep) {
"2:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-s:64:64-f80"
":128:128-n8:16:32:64-S128");
// Make sure we don't crash
- GetPointerBaseWithConstantOffset(Gep0, Offset, &TD);
- GetPointerBaseWithConstantOffset(Gep1, Offset, &TD);
- GetPointerBaseWithConstantOffset(Gep2, Offset, &TD);
- GetPointerBaseWithConstantOffset(Gep3, Offset, &TD);
+ GetPointerBaseWithConstantOffset(Gep0, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep1, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep2, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep3, Offset, TD);
// Gep of Geps
- GetElementPtrInst *GepII0 = GetElementPtrInst::Create(Gep0, C2xi32b);
- GetElementPtrInst *GepII1 = GetElementPtrInst::Create(Gep1, C2xi32a);
- GetElementPtrInst *GepII2 = GetElementPtrInst::Create(Gep2, C2xi32b);
- GetElementPtrInst *GepII3 = GetElementPtrInst::Create(Gep3, C2xi32a);
+ GetElementPtrInst *GepII0 = GetElementPtrInst::Create(I32Ty, Gep0, C2xi32b);
+ GetElementPtrInst *GepII1 = GetElementPtrInst::Create(I32Ty, Gep1, C2xi32a);
+ GetElementPtrInst *GepII2 = GetElementPtrInst::Create(I32Ty, Gep2, C2xi32b);
+ GetElementPtrInst *GepII3 = GetElementPtrInst::Create(I32Ty, Gep3, C2xi32a);
EXPECT_EQ(GepII0->getNumIndices(), 1u);
EXPECT_EQ(GepII1->getNumIndices(), 1u);
diff --git a/unittests/IR/LegacyPassManagerTest.cpp b/unittests/IR/LegacyPassManagerTest.cpp
index 9cb9414..66fd1cc 100644
--- a/unittests/IR/LegacyPassManagerTest.cpp
+++ b/unittests/IR/LegacyPassManagerTest.cpp
@@ -98,7 +98,6 @@ namespace llvm {
initializeModuleNDMPass(*PassRegistry::getPassRegistry());
}
bool runOnModule(Module &M) override {
- EXPECT_TRUE(getAnalysisIfAvailable<DataLayoutPass>());
run++;
return false;
}
@@ -175,7 +174,6 @@ namespace llvm {
initializeCGPassPass(*PassRegistry::getPassRegistry());
}
bool runOnSCC(CallGraphSCC &SCMM) override {
- EXPECT_TRUE(getAnalysisIfAvailable<DataLayoutPass>());
run();
return false;
}
@@ -214,7 +212,6 @@ namespace llvm {
return false;
}
bool runOnLoop(Loop *L, LPPassManager &LPM) override {
- EXPECT_TRUE(getAnalysisIfAvailable<DataLayoutPass>());
run();
return false;
}
@@ -251,7 +248,6 @@ namespace llvm {
return false;
}
bool runOnBasicBlock(BasicBlock &BB) override {
- EXPECT_TRUE(getAnalysisIfAvailable<DataLayoutPass>());
run();
return false;
}
@@ -276,7 +272,6 @@ namespace llvm {
initializeFPassPass(*PassRegistry::getPassRegistry());
}
bool runOnModule(Module &M) override {
- EXPECT_TRUE(getAnalysisIfAvailable<DataLayoutPass>());
for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
Function &F = *I;
{
@@ -302,7 +297,6 @@ namespace llvm {
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
legacy::PassManager Passes;
- Passes.add(new DataLayoutPass());
Passes.add(mNDM2);
Passes.add(mNDM);
Passes.add(mNDNM);
@@ -326,7 +320,6 @@ namespace llvm {
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
legacy::PassManager Passes;
- Passes.add(new DataLayoutPass());
Passes.add(mNDM);
Passes.add(mNDNM);
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
@@ -348,7 +341,6 @@ namespace llvm {
std::unique_ptr<Module> M(makeLLVMModule());
T *P = new T();
legacy::PassManager Passes;
- Passes.add(new DataLayoutPass());
Passes.add(P);
Passes.run(*M);
T::finishedOK(run);
@@ -359,7 +351,6 @@ namespace llvm {
Module *M = makeLLVMModule();
T *P = new T();
legacy::PassManager Passes;
- Passes.add(new DataLayoutPass());
Passes.add(P);
Passes.run(*M);
T::finishedOK(run, N);
@@ -397,7 +388,6 @@ namespace llvm {
SCOPED_TRACE("Running OnTheFlyTest");
struct OnTheFlyTest *O = new OnTheFlyTest();
legacy::PassManager Passes;
- Passes.add(new DataLayoutPass());
Passes.add(O);
Passes.run(*M);
diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp
index 6f2372d..51a9e0b 100644
--- a/unittests/IR/MetadataTest.cpp
+++ b/unittests/IR/MetadataTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
@@ -68,6 +69,12 @@ protected:
Metadata *MDs[] = {MD1, MD2};
return MDNode::get(Context, MDs);
}
+
+ MDSubprogram *getSubprogram() {
+ return MDSubprogram::getDistinct(Context, nullptr, "", "", nullptr, 0,
+ nullptr, false, false, 0, nullptr, 0, 0, 0,
+ 0);
+ }
};
typedef MetadataTest MDStringTest;
@@ -220,7 +227,7 @@ TEST_F(MDNodeTest, Print) {
std::string Expected;
{
raw_string_ostream OS(Expected);
- OS << "!{";
+ OS << "<" << (void *)N << "> = !{";
C->printAsOperand(OS);
OS << ", ";
S->printAsOperand(OS);
@@ -240,6 +247,105 @@ TEST_F(MDNodeTest, Print) {
EXPECT_EQ(Expected, Actual);
}
+#define EXPECT_PRINTER_EQ(EXPECTED, PRINT) \
+ do { \
+ std::string Actual_; \
+ raw_string_ostream OS(Actual_); \
+ PRINT; \
+ OS.flush(); \
+ std::string Expected_(EXPECTED); \
+ EXPECT_EQ(Expected_, Actual_); \
+ } while (false)
+
+TEST_F(MDNodeTest, PrintTemporary) {
+ MDNode *Arg = getNode();
+ TempMDNode Temp = MDNode::getTemporary(Context, Arg);
+ MDNode *N = getNode(Temp.get());
+ Module M("test", Context);
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("named");
+ NMD->addOperand(N);
+
+ EXPECT_PRINTER_EQ("!0 = !{!1}", N->print(OS, &M));
+ EXPECT_PRINTER_EQ("!1 = <temporary!> !{!2}", Temp->print(OS, &M));
+ EXPECT_PRINTER_EQ("!2 = !{}", Arg->print(OS, &M));
+
+ // Cleanup.
+ Temp->replaceAllUsesWith(Arg);
+}
+
+TEST_F(MDNodeTest, PrintFromModule) {
+ Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7);
+ MDString *S = MDString::get(Context, "foo");
+ MDNode *N0 = getNode();
+ MDNode *N1 = getNode(N0);
+ MDNode *N2 = getNode(N0, N1);
+
+ Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2};
+ MDNode *N = MDNode::get(Context, Args);
+ Module M("test", Context);
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("named");
+ NMD->addOperand(N);
+
+ std::string Expected;
+ {
+ raw_string_ostream OS(Expected);
+ OS << "!0 = !{";
+ C->printAsOperand(OS);
+ OS << ", ";
+ S->printAsOperand(OS);
+ OS << ", null, !1, !2, !3}";
+ }
+
+ EXPECT_PRINTER_EQ(Expected, N->print(OS, &M));
+}
+
+TEST_F(MDNodeTest, PrintFromFunction) {
+ Module M("test", Context);
+ auto *FTy = FunctionType::get(Type::getVoidTy(Context), false);
+ auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M);
+ auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M);
+ auto *BB0 = BasicBlock::Create(Context, "entry", F0);
+ auto *BB1 = BasicBlock::Create(Context, "entry", F1);
+ auto *R0 = ReturnInst::Create(Context, BB0);
+ auto *R1 = ReturnInst::Create(Context, BB1);
+ auto *N0 = MDNode::getDistinct(Context, None);
+ auto *N1 = MDNode::getDistinct(Context, None);
+ R0->setMetadata("md", N0);
+ R1->setMetadata("md", N1);
+
+ EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M));
+ EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M));
+}
+
+TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
+ Module M("test", Context);
+
+ auto *Intrinsic =
+ Function::Create(FunctionType::get(Type::getVoidTy(Context),
+ Type::getMetadataTy(Context), false),
+ GlobalValue::ExternalLinkage, "llvm.intrinsic", &M);
+
+ auto *FTy = FunctionType::get(Type::getVoidTy(Context), false);
+ auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M);
+ auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M);
+ auto *BB0 = BasicBlock::Create(Context, "entry", F0);
+ auto *BB1 = BasicBlock::Create(Context, "entry", F1);
+ auto *N0 = MDNode::getDistinct(Context, None);
+ auto *N1 = MDNode::getDistinct(Context, None);
+ auto *MAV0 = MetadataAsValue::get(Context, N0);
+ auto *MAV1 = MetadataAsValue::get(Context, N1);
+ CallInst::Create(Intrinsic, MAV0, "", BB0);
+ CallInst::Create(Intrinsic, MAV1, "", BB1);
+
+ EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS));
+ EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS));
+ EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false));
+ EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false));
+ EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true));
+ EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true));
+}
+#undef EXPECT_PRINTER_EQ
+
TEST_F(MDNodeTest, NullOperand) {
// metadata !{}
MDNode *Empty = MDNode::get(Context, None);
@@ -571,7 +677,7 @@ TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) {
typedef MetadataTest MDLocationTest;
TEST_F(MDLocationTest, Overflow) {
- MDNode *N = MDNode::get(Context, None);
+ MDSubprogram *N = getSubprogram();
{
MDLocation *L = MDLocation::get(Context, 2, 7, N);
EXPECT_EQ(2u, L->getLine());
@@ -596,7 +702,7 @@ TEST_F(MDLocationTest, Overflow) {
}
TEST_F(MDLocationTest, getDistinct) {
- MDNode *N = MDNode::get(Context, None);
+ MDNode *N = getSubprogram();
MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N);
EXPECT_TRUE(L0->isDistinct());
MDLocation *L1 = MDLocation::get(Context, 2, 7, N);
@@ -730,6 +836,48 @@ TEST_F(MDBasicTypeTest, getWithLargeValues) {
EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits());
}
+TEST_F(MDBasicTypeTest, getUnspecified) {
+ auto *N =
+ MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, "unspecified");
+ EXPECT_EQ(dwarf::DW_TAG_unspecified_type, N->getTag());
+ EXPECT_EQ("unspecified", N->getName());
+ EXPECT_EQ(0u, N->getSizeInBits());
+ EXPECT_EQ(0u, N->getAlignInBits());
+ EXPECT_EQ(0u, N->getEncoding());
+ EXPECT_EQ(0u, N->getLine());
+}
+
+typedef MetadataTest MDTypeTest;
+
+TEST_F(MDTypeTest, clone) {
+ // Check that MDType has a specialized clone that returns TempMDType.
+ MDType *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32,
+ dwarf::DW_ATE_signed);
+
+ TempMDType Temp = N->clone();
+ EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
+}
+
+TEST_F(MDTypeTest, setFlags) {
+ // void (void)
+ Metadata *TypesOps[] = {nullptr};
+ Metadata *Types = MDTuple::get(Context, TypesOps);
+
+ MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types);
+ EXPECT_EQ(0u, D->getFlags());
+ D->setFlags(DIDescriptor::FlagRValueReference);
+ EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags());
+ D->setFlags(0u);
+ EXPECT_EQ(0u, D->getFlags());
+
+ TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types);
+ EXPECT_EQ(0u, T->getFlags());
+ T->setFlags(DIDescriptor::FlagRValueReference);
+ EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags());
+ T->setFlags(0u);
+ EXPECT_EQ(0u, T->getFlags());
+}
+
typedef MetadataTest MDDerivedTypeTest;
TEST_F(MDDerivedTypeTest, get) {
@@ -1041,6 +1189,12 @@ TEST_F(MDFileTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+TEST_F(MDFileTest, ScopeGetFile) {
+ // Ensure that MDScope::getFile() returns itself.
+ MDScope *N = MDFile::get(Context, "file", "dir");
+ EXPECT_EQ(N, N->getFile());
+}
+
typedef MetadataTest MDCompileUnitTest;
TEST_F(MDCompileUnitTest, get) {
@@ -1568,7 +1722,9 @@ TEST_F(MDLocalVariableTest, get) {
Metadata *Type = MDTuple::getDistinct(Context, None);
unsigned Arg = 6;
unsigned Flags = 7;
- Metadata *InlinedAt = MDTuple::getDistinct(Context, None);
+ Metadata *InlinedAtScope = MDTuple::getDistinct(Context, None);
+ Metadata *InlinedAt =
+ MDLocation::getDistinct(Context, 10, 20, InlinedAtScope);
auto *N = MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
Arg, Flags, InlinedAt);
@@ -1606,6 +1762,19 @@ TEST_F(MDLocalVariableTest, get) {
TempMDLocalVariable Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
+
+ auto *Inlined = N->withoutInline();
+ EXPECT_NE(N, Inlined);
+ EXPECT_EQ(N->getTag(), Inlined->getTag());
+ EXPECT_EQ(N->getScope(), Inlined->getScope());
+ EXPECT_EQ(N->getName(), Inlined->getName());
+ EXPECT_EQ(N->getFile(), Inlined->getFile());
+ EXPECT_EQ(N->getLine(), Inlined->getLine());
+ EXPECT_EQ(N->getType(), Inlined->getType());
+ EXPECT_EQ(N->getArg(), Inlined->getArg());
+ EXPECT_EQ(N->getFlags(), Inlined->getFlags());
+ EXPECT_EQ(nullptr, Inlined->getInlinedAt());
+ EXPECT_EQ(N, Inlined->withInline(cast<MDLocation>(InlinedAt)));
}
typedef MetadataTest MDExpressionTest;