• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 "public_internal.h"
19 #include "jobs/service.h"
20 #include "type/type_system.h"
21 #include "value/abstract_typed_value.h"
22 
23 #include "util/tests/verifier_test.h"
24 
25 #include <gtest/gtest.h>
26 
27 #include <functional>
28 
29 namespace ark::verifier::test {
30 
TEST_F(VerifierTest,AbsIntRegContext)31 TEST_F(VerifierTest, AbsIntRegContext)
32 {
33     using Builtin = Type::Builtin;
34     auto *config = NewConfig();
35     RuntimeOptions runtimeOpts;
36     Runtime::Create(runtimeOpts);
37     auto *service = CreateService(config, Runtime::GetCurrent()->GetInternalAllocator(),
38                                   Runtime::GetCurrent()->GetClassLinker(), "");
39     TypeSystem typeSystem(service->verifierService);
40     Variables variables;
41 
42     auto i16 = Type {Builtin::I16};
43     auto i32 = Type {Builtin::I32};
44 
45     auto u16 = Type {Builtin::U16};
46 
47     auto nv = [&variables] { return variables.NewVar(); };
48 
49     AbstractTypedValue av1 {i16, nv()};
50     AbstractTypedValue av2 {i32, nv()};
51     AbstractTypedValue av3 {u16, nv()};
52 
53     RegContext ctx1;
54     RegContext ctx2;
55 
56     ctx1[-1] = av1;
57     ctx2[0] = av2;
58 
59     auto ctx3 = RcUnion(&ctx1, &ctx2, &typeSystem);
60 
61     ctx3.RemoveInconsistentRegs();
62     EXPECT_EQ(ctx3.Size(), 0);
63 
64     ctx1[0] = av1;
65 
66     ctx3 = RcUnion(&ctx1, &ctx2, &typeSystem);
67 
68     ctx3.RemoveInconsistentRegs();
69     EXPECT_EQ(ctx3.Size(), 1);
70 
71     EXPECT_EQ(ctx3[0].GetAbstractType(), i32);
72 
73     DestroyService(service, false);
74     DestroyConfig(config);
75 }
76 
77 }  // namespace ark::verifier::test
78