diff options
author | Thomas Lively <tlively@google.com> | 2023-10-25 20:55:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 20:55:27 +0200 |
commit | a09ea699d69ed54741d95b9b5fa2247bdcf28152 (patch) | |
tree | 3bb1d68c93a3ca6b03671fc7ba4a966dd7a7dd8a /test/gtest | |
parent | 2b6566341cf316cc18486e96d54e8d8dd9a57a5b (diff) | |
download | binaryen-a09ea699d69ed54741d95b9b5fa2247bdcf28152.tar.gz binaryen-a09ea699d69ed54741d95b9b5fa2247bdcf28152.tar.bz2 binaryen-a09ea699d69ed54741d95b9b5fa2247bdcf28152.zip |
[analysis] Implement an Int lattice (#6037)
Implement a generic lattice template for integral types ordered by `<`.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/lattices.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
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); +} |