[AMDGPU] Add True16 register classes.
[llvm-project.git] / clang / unittests / Analysis / FlowSensitive / DebugSupportTest.cpp
blob22bf8cadd1116fff88ea2cc81d75c9f043ea8a22
1 //===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --------------===//
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 "clang/Analysis/FlowSensitive/DebugSupport.h"
10 #include "TestingSupport.h"
11 #include "clang/Analysis/FlowSensitive/Formula.h"
12 #include "llvm/Support/ScopedPrinter.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
17 namespace {
19 using namespace clang;
20 using namespace dataflow;
22 using test::ConstraintContext;
23 using testing::StrEq;
25 TEST(BoolValueDebugStringTest, AtomicBoolean) {
26 ConstraintContext Ctx;
27 auto B = Ctx.atom();
29 auto Expected = "V0";
30 EXPECT_THAT(llvm::to_string(*B), StrEq(Expected));
33 TEST(BoolValueDebugStringTest, Negation) {
34 ConstraintContext Ctx;
35 auto B = Ctx.neg(Ctx.atom());
37 auto Expected = "!V0";
38 EXPECT_THAT(llvm::to_string(*B), StrEq(Expected));
41 TEST(BoolValueDebugStringTest, Conjunction) {
42 ConstraintContext Ctx;
43 auto *V0 = Ctx.atom();
44 auto *V1 = Ctx.atom();
45 EXPECT_EQ("(V0 & V1)", llvm::to_string(*Ctx.conj(V0, V1)));
48 TEST(BoolValueDebugStringTest, Disjunction) {
49 ConstraintContext Ctx;
50 auto *V0 = Ctx.atom();
51 auto *V1 = Ctx.atom();
52 EXPECT_EQ("(V0 | V1)", llvm::to_string(*Ctx.disj(V0, V1)));
55 TEST(BoolValueDebugStringTest, Implication) {
56 ConstraintContext Ctx;
57 auto *V0 = Ctx.atom();
58 auto *V1 = Ctx.atom();
59 EXPECT_EQ("(V0 => V1)", llvm::to_string(*Ctx.impl(V0, V1)));
62 TEST(BoolValueDebugStringTest, Iff) {
63 ConstraintContext Ctx;
64 auto *V0 = Ctx.atom();
65 auto *V1 = Ctx.atom();
66 EXPECT_EQ("(V0 = V1)", llvm::to_string(*Ctx.iff(V0, V1)));
69 TEST(BoolValueDebugStringTest, Xor) {
70 ConstraintContext Ctx;
71 auto V0 = Ctx.atom();
72 auto V1 = Ctx.atom();
73 auto B = Ctx.disj(Ctx.conj(V0, Ctx.neg(V1)), Ctx.conj(Ctx.neg(V0), V1));
75 auto Expected = "((V0 & !V1) | (!V0 & V1))";
76 EXPECT_THAT(llvm::to_string(*B), StrEq(Expected));
79 TEST(BoolValueDebugStringTest, NestedBoolean) {
80 ConstraintContext Ctx;
81 auto V0 = Ctx.atom();
82 auto V1 = Ctx.atom();
83 auto V2 = Ctx.atom();
84 auto V3 = Ctx.atom();
85 auto V4 = Ctx.atom();
86 auto B = Ctx.conj(V0, Ctx.disj(V1, Ctx.conj(V2, Ctx.disj(V3, V4))));
88 auto Expected = "(V0 & (V1 | (V2 & (V3 | V4))))";
89 EXPECT_THAT(llvm::to_string(*B), StrEq(Expected));
92 TEST(BoolValueDebugStringTest, ComplexBooleanWithSomeNames) {
93 ConstraintContext Ctx;
94 auto True = Ctx.atom();
95 auto False = Ctx.atom();
96 auto V2 = Ctx.atom();
97 auto V3 = Ctx.atom();
98 Formula::AtomNames Names;
99 Names[True->getAtom()] = "true";
100 Names[False->getAtom()] = "false";
101 auto B = Ctx.disj(Ctx.conj(False, V2), Ctx.disj(True, V3));
103 auto Expected = R"(((false & V2) | (true | V3)))";
104 std::string Actual;
105 llvm::raw_string_ostream OS(Actual);
106 B->print(OS, &Names);
107 EXPECT_THAT(Actual, StrEq(Expected));
110 } // namespace