From a09ea699d69ed54741d95b9b5fa2247bdcf28152 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 25 Oct 2023 20:55:27 +0200 Subject: [analysis] Implement an Int lattice (#6037) Implement a generic lattice template for integral types ordered by `<`. --- test/gtest/lattices.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/gtest/lattices.cpp') diff --git a/test/gtest/lattices.cpp b/test/gtest/lattices.cpp index f06ba612b..d72e088fc 100644 --- a/test/gtest/lattices.cpp +++ b/test/gtest/lattices.cpp @@ -15,6 +15,7 @@ */ #include "analysis/lattices/bool.h" +#include "analysis/lattices/int.h" #include "gtest/gtest.h" using namespace wasm; @@ -48,3 +49,38 @@ TEST(BoolLattice, Join) { EXPECT_FALSE(lattice.join(elem, true)); ASSERT_TRUE(elem); } + +TEST(IntLattice, GetBottom) { + analysis::Int32 int32; + EXPECT_EQ(int32.getBottom(), (int32_t)(1ll << 31)); + + analysis::Int64 int64; + EXPECT_EQ(int64.getBottom(), (int64_t)(1ll << 63)); + + analysis::UInt32 uint32; + EXPECT_EQ(uint32.getBottom(), (uint32_t)0); + + analysis::UInt64 uint64; + EXPECT_EQ(uint64.getBottom(), (uint32_t)0); +} + +TEST(IntLattice, Compare) { + analysis::Int32 int32; + EXPECT_EQ(int32.compare(-5, 42), analysis::LESS); + EXPECT_EQ(int32.compare(42, -5), analysis::GREATER); + EXPECT_EQ(int32.compare(42, 42), analysis::EQUAL); +} + +TEST(IntLattice, Join) { + analysis::Int32 int32; + int elem = 0; + + EXPECT_FALSE(int32.join(elem, -10)); + ASSERT_EQ(elem, 0); + + EXPECT_FALSE(int32.join(elem, 0)); + ASSERT_EQ(elem, 0); + + EXPECT_TRUE(int32.join(elem, 100)); + ASSERT_EQ(elem, 100); +} -- cgit v1.2.3