[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / unittests / IR / DebugInfoTest.cpp
blob93247908d8a77fd263e4c0a93e3771c22f09873a
1 //===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/DebugInfoMetadata.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 TEST(DINodeTest, getFlag) {
17 // Some valid flags.
18 EXPECT_EQ(DINode::FlagPublic, DINode::getFlag("DIFlagPublic"));
19 EXPECT_EQ(DINode::FlagProtected, DINode::getFlag("DIFlagProtected"));
20 EXPECT_EQ(DINode::FlagPrivate, DINode::getFlag("DIFlagPrivate"));
21 EXPECT_EQ(DINode::FlagVector, DINode::getFlag("DIFlagVector"));
22 EXPECT_EQ(DINode::FlagRValueReference,
23 DINode::getFlag("DIFlagRValueReference"));
25 // FlagAccessibility shouldn't work.
26 EXPECT_EQ(0u, DINode::getFlag("DIFlagAccessibility"));
28 // Some other invalid strings.
29 EXPECT_EQ(0u, DINode::getFlag("FlagVector"));
30 EXPECT_EQ(0u, DINode::getFlag("Vector"));
31 EXPECT_EQ(0u, DINode::getFlag("other things"));
32 EXPECT_EQ(0u, DINode::getFlag("DIFlagOther"));
35 TEST(DINodeTest, getFlagString) {
36 // Some valid flags.
37 EXPECT_EQ(StringRef("DIFlagPublic"),
38 DINode::getFlagString(DINode::FlagPublic));
39 EXPECT_EQ(StringRef("DIFlagProtected"),
40 DINode::getFlagString(DINode::FlagProtected));
41 EXPECT_EQ(StringRef("DIFlagPrivate"),
42 DINode::getFlagString(DINode::FlagPrivate));
43 EXPECT_EQ(StringRef("DIFlagVector"),
44 DINode::getFlagString(DINode::FlagVector));
45 EXPECT_EQ(StringRef("DIFlagRValueReference"),
46 DINode::getFlagString(DINode::FlagRValueReference));
48 // FlagAccessibility actually equals FlagPublic.
49 EXPECT_EQ(StringRef("DIFlagPublic"),
50 DINode::getFlagString(DINode::FlagAccessibility));
52 // Some other invalid flags.
53 EXPECT_EQ(StringRef(),
54 DINode::getFlagString(DINode::FlagPublic | DINode::FlagVector));
55 EXPECT_EQ(StringRef(), DINode::getFlagString(DINode::FlagFwdDecl |
56 DINode::FlagArtificial));
57 EXPECT_EQ(StringRef(),
58 DINode::getFlagString(static_cast<DINode::DIFlags>(0xffff)));
61 TEST(DINodeTest, splitFlags) {
62 // Some valid flags.
63 #define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER) \
64 { \
65 SmallVector<DINode::DIFlags, 8> V; \
66 EXPECT_EQ(REMAINDER, DINode::splitFlags(FLAGS, V)); \
67 EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
69 CHECK_SPLIT(DINode::FlagPublic, {DINode::FlagPublic}, DINode::FlagZero);
70 CHECK_SPLIT(DINode::FlagProtected, {DINode::FlagProtected}, DINode::FlagZero);
71 CHECK_SPLIT(DINode::FlagPrivate, {DINode::FlagPrivate}, DINode::FlagZero);
72 CHECK_SPLIT(DINode::FlagVector, {DINode::FlagVector}, DINode::FlagZero);
73 CHECK_SPLIT(DINode::FlagRValueReference, {DINode::FlagRValueReference},
74 DINode::FlagZero);
75 DINode::DIFlags Flags[] = {DINode::FlagFwdDecl, DINode::FlagVector};
76 CHECK_SPLIT(DINode::FlagFwdDecl | DINode::FlagVector, Flags,
77 DINode::FlagZero);
78 CHECK_SPLIT(DINode::FlagZero, {}, DINode::FlagZero);
79 #undef CHECK_SPLIT
82 } // end namespace