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(DebugNodeTest,getFlag)17 TEST(DebugNodeTest, getFlag) {
18   // Some valid flags.
19   EXPECT_EQ(DebugNode::FlagPublic, DebugNode::getFlag("DIFlagPublic"));
20   EXPECT_EQ(DebugNode::FlagProtected, DebugNode::getFlag("DIFlagProtected"));
21   EXPECT_EQ(DebugNode::FlagPrivate, DebugNode::getFlag("DIFlagPrivate"));
22   EXPECT_EQ(DebugNode::FlagVector, DebugNode::getFlag("DIFlagVector"));
23   EXPECT_EQ(DebugNode::FlagRValueReference,
24             DebugNode::getFlag("DIFlagRValueReference"));
25 
26   // FlagAccessibility shouldn't work.
27   EXPECT_EQ(0u, DebugNode::getFlag("DIFlagAccessibility"));
28 
29   // Some other invalid strings.
30   EXPECT_EQ(0u, DebugNode::getFlag("FlagVector"));
31   EXPECT_EQ(0u, DebugNode::getFlag("Vector"));
32   EXPECT_EQ(0u, DebugNode::getFlag("other things"));
33   EXPECT_EQ(0u, DebugNode::getFlag("DIFlagOther"));
34 }
35 
TEST(DebugNodeTest,getFlagString)36 TEST(DebugNodeTest, getFlagString) {
37   // Some valid flags.
38   EXPECT_EQ(StringRef("DIFlagPublic"),
39             DebugNode::getFlagString(DebugNode::FlagPublic));
40   EXPECT_EQ(StringRef("DIFlagProtected"),
41             DebugNode::getFlagString(DebugNode::FlagProtected));
42   EXPECT_EQ(StringRef("DIFlagPrivate"),
43             DebugNode::getFlagString(DebugNode::FlagPrivate));
44   EXPECT_EQ(StringRef("DIFlagVector"),
45             DebugNode::getFlagString(DebugNode::FlagVector));
46   EXPECT_EQ(StringRef("DIFlagRValueReference"),
47             DebugNode::getFlagString(DebugNode::FlagRValueReference));
48 
49   // FlagAccessibility actually equals FlagPublic.
50   EXPECT_EQ(StringRef("DIFlagPublic"),
51             DebugNode::getFlagString(DebugNode::FlagAccessibility));
52 
53   // Some other invalid flags.
54   EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagPublic |
55                                                   DebugNode::FlagVector));
56   EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagFwdDecl |
57                                                   DebugNode::FlagArtificial));
58   EXPECT_EQ(StringRef(), DebugNode::getFlagString(0xffff));
59 }
60 
TEST(DebugNodeTest,splitFlags)61 TEST(DebugNodeTest, splitFlags) {
62 // Some valid flags.
63 #define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER)                                  \
64   {                                                                            \
65     SmallVector<unsigned, 8> V;                                                \
66     EXPECT_EQ(REMAINDER, DebugNode::splitFlags(FLAGS, V));                     \
67     EXPECT_TRUE(makeArrayRef(V).equals(VECTOR));                               \
68   }
69   CHECK_SPLIT(DebugNode::FlagPublic, {DebugNode::FlagPublic}, 0u);
70   CHECK_SPLIT(DebugNode::FlagProtected, {DebugNode::FlagProtected}, 0u);
71   CHECK_SPLIT(DebugNode::FlagPrivate, {DebugNode::FlagPrivate}, 0u);
72   CHECK_SPLIT(DebugNode::FlagVector, {DebugNode::FlagVector}, 0u);
73   CHECK_SPLIT(DebugNode::FlagRValueReference, {DebugNode::FlagRValueReference},
74               0u);
75   unsigned Flags[] = {DebugNode::FlagFwdDecl, DebugNode::FlagVector};
76   CHECK_SPLIT(DebugNode::FlagFwdDecl | DebugNode::FlagVector, Flags, 0u);
77   CHECK_SPLIT(0x100000u, {}, 0x100000u);
78   CHECK_SPLIT(0x100000u | DebugNode::FlagVector, {DebugNode::FlagVector},
79               0x100000u);
80 #undef CHECK_SPLIT
81 }
82 
83 } // end namespace
84