2014-10-04 04:01:09 +08: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 09:21:40 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2014-10-04 04:01:09 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
TEST(DINodeTest, getFlag) {
|
2015-02-21 08:43:09 +08:00
|
|
|
// Some valid flags.
|
2015-04-30 00:38:44 +08:00
|
|
|
EXPECT_EQ(DINode::FlagPublic, DINode::getFlag("DIFlagPublic"));
|
|
|
|
EXPECT_EQ(DINode::FlagProtected, DINode::getFlag("DIFlagProtected"));
|
|
|
|
EXPECT_EQ(DINode::FlagPrivate, DINode::getFlag("DIFlagPrivate"));
|
|
|
|
EXPECT_EQ(DINode::FlagVector, DINode::getFlag("DIFlagVector"));
|
|
|
|
EXPECT_EQ(DINode::FlagRValueReference,
|
|
|
|
DINode::getFlag("DIFlagRValueReference"));
|
2015-02-21 08:43:09 +08:00
|
|
|
|
|
|
|
// FlagAccessibility shouldn't work.
|
2015-04-30 00:38:44 +08:00
|
|
|
EXPECT_EQ(0u, DINode::getFlag("DIFlagAccessibility"));
|
2015-02-21 08:43:09 +08:00
|
|
|
|
|
|
|
// Some other invalid strings.
|
2015-04-30 00:38:44 +08:00
|
|
|
EXPECT_EQ(0u, DINode::getFlag("FlagVector"));
|
|
|
|
EXPECT_EQ(0u, DINode::getFlag("Vector"));
|
|
|
|
EXPECT_EQ(0u, DINode::getFlag("other things"));
|
|
|
|
EXPECT_EQ(0u, DINode::getFlag("DIFlagOther"));
|
2015-02-21 08:43:09 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
TEST(DINodeTest, getFlagString) {
|
2015-02-21 08:43:09 +08:00
|
|
|
// Some valid flags.
|
|
|
|
EXPECT_EQ(StringRef("DIFlagPublic"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagPublic));
|
2015-02-21 08:43:09 +08:00
|
|
|
EXPECT_EQ(StringRef("DIFlagProtected"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagProtected));
|
2015-02-21 08:43:09 +08:00
|
|
|
EXPECT_EQ(StringRef("DIFlagPrivate"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagPrivate));
|
2015-02-21 08:43:09 +08:00
|
|
|
EXPECT_EQ(StringRef("DIFlagVector"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagVector));
|
2015-02-21 08:43:09 +08:00
|
|
|
EXPECT_EQ(StringRef("DIFlagRValueReference"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagRValueReference));
|
2015-02-21 08:43:09 +08:00
|
|
|
|
|
|
|
// FlagAccessibility actually equals FlagPublic.
|
|
|
|
EXPECT_EQ(StringRef("DIFlagPublic"),
|
2015-04-30 00:38:44 +08:00
|
|
|
DINode::getFlagString(DINode::FlagAccessibility));
|
2015-02-21 08:43:09 +08:00
|
|
|
|
|
|
|
// Some other invalid flags.
|
2015-04-30 00:38:44 +08:00
|
|
|
EXPECT_EQ(StringRef(),
|
|
|
|
DINode::getFlagString(DINode::FlagPublic | DINode::FlagVector));
|
|
|
|
EXPECT_EQ(StringRef(), DINode::getFlagString(DINode::FlagFwdDecl |
|
|
|
|
DINode::FlagArtificial));
|
|
|
|
EXPECT_EQ(StringRef(), DINode::getFlagString(0xffff));
|
2015-02-21 08:43:09 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
TEST(DINodeTest, splitFlags) {
|
2015-04-07 09:21:40 +08:00
|
|
|
// Some valid flags.
|
2015-02-21 08:45:26 +08:00
|
|
|
#define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER) \
|
|
|
|
{ \
|
|
|
|
SmallVector<unsigned, 8> V; \
|
2015-04-30 00:38:44 +08:00
|
|
|
EXPECT_EQ(REMAINDER, DINode::splitFlags(FLAGS, V)); \
|
2015-04-07 09:21:40 +08:00
|
|
|
EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
|
2015-02-21 08:45:26 +08:00
|
|
|
}
|
2015-04-30 00:38:44 +08:00
|
|
|
CHECK_SPLIT(DINode::FlagPublic, {DINode::FlagPublic}, 0u);
|
|
|
|
CHECK_SPLIT(DINode::FlagProtected, {DINode::FlagProtected}, 0u);
|
|
|
|
CHECK_SPLIT(DINode::FlagPrivate, {DINode::FlagPrivate}, 0u);
|
|
|
|
CHECK_SPLIT(DINode::FlagVector, {DINode::FlagVector}, 0u);
|
|
|
|
CHECK_SPLIT(DINode::FlagRValueReference, {DINode::FlagRValueReference}, 0u);
|
|
|
|
unsigned Flags[] = {DINode::FlagFwdDecl, DINode::FlagVector};
|
|
|
|
CHECK_SPLIT(DINode::FlagFwdDecl | DINode::FlagVector, Flags, 0u);
|
2015-03-02 05:28:53 +08:00
|
|
|
CHECK_SPLIT(0x100000u, {}, 0x100000u);
|
2015-04-30 00:38:44 +08:00
|
|
|
CHECK_SPLIT(0x100000u | DINode::FlagVector, {DINode::FlagVector}, 0x100000u);
|
2015-02-21 08:45:26 +08:00
|
|
|
#undef CHECK_SPLIT
|
|
|
|
}
|
|
|
|
|
2014-10-04 04:01:09 +08:00
|
|
|
} // end namespace
|