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