2014-10-03 20:01:09 +00:00
|
|
|
//===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-04-07 01:21:40 +00:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2014-10-03 20:01:09 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-04-07 01:21:40 +00:00
|
|
|
TEST(DebugNodeTest, getFlag) {
|
2015-02-21 00:43:09 +00:00
|
|
|
// Some valid flags.
|
2015-04-07 01:21:40 +00:00
|
|
|
EXPECT_EQ(DebugNode::FlagPublic, DebugNode::getFlag("DIFlagPublic"));
|
|
|
|
EXPECT_EQ(DebugNode::FlagProtected, DebugNode::getFlag("DIFlagProtected"));
|
|
|
|
EXPECT_EQ(DebugNode::FlagPrivate, DebugNode::getFlag("DIFlagPrivate"));
|
|
|
|
EXPECT_EQ(DebugNode::FlagVector, DebugNode::getFlag("DIFlagVector"));
|
|
|
|
EXPECT_EQ(DebugNode::FlagRValueReference,
|
|
|
|
DebugNode::getFlag("DIFlagRValueReference"));
|
2015-02-21 00:43:09 +00:00
|
|
|
|
|
|
|
// FlagAccessibility shouldn't work.
|
2015-04-07 01:21:40 +00:00
|
|
|
EXPECT_EQ(0u, DebugNode::getFlag("DIFlagAccessibility"));
|
2015-02-21 00:43:09 +00:00
|
|
|
|
|
|
|
// Some other invalid strings.
|
2015-04-07 01:21:40 +00:00
|
|
|
EXPECT_EQ(0u, DebugNode::getFlag("FlagVector"));
|
|
|
|
EXPECT_EQ(0u, DebugNode::getFlag("Vector"));
|
|
|
|
EXPECT_EQ(0u, DebugNode::getFlag("other things"));
|
|
|
|
EXPECT_EQ(0u, DebugNode::getFlag("DIFlagOther"));
|
2015-02-21 00:43:09 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 01:21:40 +00:00
|
|
|
TEST(DebugNodeTest, getFlagString) {
|
2015-02-21 00:43:09 +00:00
|
|
|
// Some valid flags.
|
|
|
|
EXPECT_EQ(StringRef("DIFlagPublic"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagPublic));
|
2015-02-21 00:43:09 +00:00
|
|
|
EXPECT_EQ(StringRef("DIFlagProtected"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagProtected));
|
2015-02-21 00:43:09 +00:00
|
|
|
EXPECT_EQ(StringRef("DIFlagPrivate"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagPrivate));
|
2015-02-21 00:43:09 +00:00
|
|
|
EXPECT_EQ(StringRef("DIFlagVector"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagVector));
|
2015-02-21 00:43:09 +00:00
|
|
|
EXPECT_EQ(StringRef("DIFlagRValueReference"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagRValueReference));
|
2015-02-21 00:43:09 +00:00
|
|
|
|
|
|
|
// FlagAccessibility actually equals FlagPublic.
|
|
|
|
EXPECT_EQ(StringRef("DIFlagPublic"),
|
2015-04-07 01:21:40 +00:00
|
|
|
DebugNode::getFlagString(DebugNode::FlagAccessibility));
|
2015-02-21 00:43:09 +00:00
|
|
|
|
|
|
|
// Some other invalid flags.
|
2015-04-07 01:21:40 +00:00
|
|
|
EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagPublic |
|
|
|
|
DebugNode::FlagVector));
|
|
|
|
EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagFwdDecl |
|
|
|
|
DebugNode::FlagArtificial));
|
|
|
|
EXPECT_EQ(StringRef(), DebugNode::getFlagString(0xffff));
|
2015-02-21 00:43:09 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 01:21:40 +00:00
|
|
|
TEST(DebugNodeTest, splitFlags) {
|
|
|
|
// Some valid flags.
|
2015-02-21 00:45:26 +00:00
|
|
|
#define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER) \
|
|
|
|
{ \
|
|
|
|
SmallVector<unsigned, 8> V; \
|
2015-04-07 01:21:40 +00:00
|
|
|
EXPECT_EQ(REMAINDER, DebugNode::splitFlags(FLAGS, V)); \
|
|
|
|
EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
|
2015-02-21 00:45:26 +00:00
|
|
|
}
|
2015-04-07 01:21:40 +00:00
|
|
|
CHECK_SPLIT(DebugNode::FlagPublic, {DebugNode::FlagPublic}, 0u);
|
|
|
|
CHECK_SPLIT(DebugNode::FlagProtected, {DebugNode::FlagProtected}, 0u);
|
|
|
|
CHECK_SPLIT(DebugNode::FlagPrivate, {DebugNode::FlagPrivate}, 0u);
|
|
|
|
CHECK_SPLIT(DebugNode::FlagVector, {DebugNode::FlagVector}, 0u);
|
|
|
|
CHECK_SPLIT(DebugNode::FlagRValueReference, {DebugNode::FlagRValueReference},
|
|
|
|
0u);
|
|
|
|
unsigned Flags[] = {DebugNode::FlagFwdDecl, DebugNode::FlagVector};
|
|
|
|
CHECK_SPLIT(DebugNode::FlagFwdDecl | DebugNode::FlagVector, Flags, 0u);
|
2015-03-01 21:28:53 +00:00
|
|
|
CHECK_SPLIT(0x100000u, {}, 0x100000u);
|
2015-04-07 01:21:40 +00:00
|
|
|
CHECK_SPLIT(0x100000u | DebugNode::FlagVector, {DebugNode::FlagVector},
|
2015-02-21 00:45:26 +00:00
|
|
|
0x100000u);
|
|
|
|
#undef CHECK_SPLIT
|
|
|
|
}
|
|
|
|
|
2014-10-03 20:01:09 +00:00
|
|
|
} // end namespace
|