• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "absint/reg_context.h"
17 
18 #include "value/abstract_typed_value.h"
19 #include "type/type_system.h"
20 #include "type/type_sort.h"
21 #include "type/type_image.h"
22 
23 #include "util/tests/verifier_test.h"
24 
25 #include <gtest/gtest.h>
26 
27 #include <functional>
28 
29 namespace panda::verifier::test {
30 
TEST_F(VerifierTest,AbsIntRegContext)31 TEST_F(VerifierTest, AbsIntRegContext)
32 {
33     SortNames<PandaString> sort {"Bot", "Top"};
34     TypeSystem type_system {sort["Bot"], sort["Top"]};
35     Variables variables;
36 
37     auto i8 = type_system.Parametric(sort["i8"])();
38     auto i16 = type_system.Parametric(sort["i16"])();
39     auto i32 = type_system.Parametric(sort["i32"])();
40     auto i64 = type_system.Parametric(sort["i64"])();
41 
42     i8 << i16 << i32 << i64;
43 
44     auto u8 = type_system.Parametric(sort["u8"])();
45     auto u16 = type_system.Parametric(sort["u16"])();
46     auto u32 = type_system.Parametric(sort["u32"])();
47     auto u64 = type_system.Parametric(sort["u64"])();
48 
49     u8 << u16 << u32 << u64;
50 
51     auto nv = std::bind(&Variables::NewVar, variables);
52 
53     AbstractTypedValue av1 {i16, nv()};
54     AbstractTypedValue av2 {i32, nv()};
55     AbstractTypedValue av3 {u16, nv()};
56 
57     RegContext ctx1, ctx2;
58 
59     ctx1[-1] = av1;
60     ctx2[0] = av2;
61 
62     auto ctx3 = ctx1 & ctx2;
63 
64     ctx3.RemoveInconsistentRegs();
65     EXPECT_EQ(ctx3.Size(), 0);
66 
67     ctx1[0] = av1;
68 
69     ctx3 = ctx1 & ctx2;
70 
71     ctx3.RemoveInconsistentRegs();
72     EXPECT_EQ(ctx3.Size(), 1);
73 
74     EXPECT_EQ(ctx3[0].GetAbstractType().GetType(), i32);
75 }
76 
77 }  // namespace panda::verifier::test
78