• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/IR/DebugInfoMetadata.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 
15 namespace {
16 
TEST(DINodeTest,getFlag)17 TEST(DINodeTest, getFlag) {
18   // Some valid flags.
19   EXPECT_EQ(DINode::FlagPublic, DINode::getFlag("DIFlagPublic"));
20   EXPECT_EQ(DINode::FlagProtected, DINode::getFlag("DIFlagProtected"));
21   EXPECT_EQ(DINode::FlagPrivate, DINode::getFlag("DIFlagPrivate"));
22   EXPECT_EQ(DINode::FlagVector, DINode::getFlag("DIFlagVector"));
23   EXPECT_EQ(DINode::FlagRValueReference,
24             DINode::getFlag("DIFlagRValueReference"));
25 
26   // FlagAccessibility shouldn't work.
27   EXPECT_EQ(0u, DINode::getFlag("DIFlagAccessibility"));
28 
29   // Some other invalid strings.
30   EXPECT_EQ(0u, DINode::getFlag("FlagVector"));
31   EXPECT_EQ(0u, DINode::getFlag("Vector"));
32   EXPECT_EQ(0u, DINode::getFlag("other things"));
33   EXPECT_EQ(0u, DINode::getFlag("DIFlagOther"));
34 }
35 
TEST(DINodeTest,getFlagString)36 TEST(DINodeTest, getFlagString) {
37   // Some valid flags.
38   EXPECT_EQ(StringRef("DIFlagPublic"),
39             DINode::getFlagString(DINode::FlagPublic));
40   EXPECT_EQ(StringRef("DIFlagProtected"),
41             DINode::getFlagString(DINode::FlagProtected));
42   EXPECT_EQ(StringRef("DIFlagPrivate"),
43             DINode::getFlagString(DINode::FlagPrivate));
44   EXPECT_EQ(StringRef("DIFlagVector"),
45             DINode::getFlagString(DINode::FlagVector));
46   EXPECT_EQ(StringRef("DIFlagRValueReference"),
47             DINode::getFlagString(DINode::FlagRValueReference));
48 
49   // FlagAccessibility actually equals FlagPublic.
50   EXPECT_EQ(StringRef("DIFlagPublic"),
51             DINode::getFlagString(DINode::FlagAccessibility));
52 
53   // Some other invalid flags.
54   EXPECT_EQ(StringRef(),
55             DINode::getFlagString(DINode::FlagPublic | DINode::FlagVector));
56   EXPECT_EQ(StringRef(), DINode::getFlagString(DINode::FlagFwdDecl |
57                                                DINode::FlagArtificial));
58   EXPECT_EQ(StringRef(), DINode::getFlagString(0xffff));
59 }
60 
TEST(DINodeTest,splitFlags)61 TEST(DINodeTest, splitFlags) {
62 // Some valid flags.
63 #define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER)                                  \
64   {                                                                            \
65     SmallVector<unsigned, 8> V;                                                \
66     EXPECT_EQ(REMAINDER, DINode::splitFlags(FLAGS, V));                        \
67     EXPECT_TRUE(makeArrayRef(V).equals(VECTOR));                               \
68   }
69   CHECK_SPLIT(DINode::FlagPublic, {DINode::FlagPublic}, 0u);
70   CHECK_SPLIT(DINode::FlagProtected, {DINode::FlagProtected}, 0u);
71   CHECK_SPLIT(DINode::FlagPrivate, {DINode::FlagPrivate}, 0u);
72   CHECK_SPLIT(DINode::FlagVector, {DINode::FlagVector}, 0u);
73   CHECK_SPLIT(DINode::FlagRValueReference, {DINode::FlagRValueReference}, 0u);
74   unsigned Flags[] = {DINode::FlagFwdDecl, DINode::FlagVector};
75   CHECK_SPLIT(DINode::FlagFwdDecl | DINode::FlagVector, Flags, 0u);
76   CHECK_SPLIT(0x100000u, {}, 0x100000u);
77   CHECK_SPLIT(0x100000u | DINode::FlagVector, {DINode::FlagVector}, 0x100000u);
78 #undef CHECK_SPLIT
79 }
80 
81 } // end namespace
82