diff options
author | Thomas Lively <tlively@google.com> | 2024-04-29 10:19:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 10:19:56 -0700 |
commit | a7c434bdc98025f182cadac74e6a2a3cd0359f60 (patch) | |
tree | d47052a1c7e1899d7f2fd59084a75a7b7a2d8494 /test/gtest | |
parent | 7750570957315d21b556538375012c242d2695d6 (diff) | |
download | binaryen-a7c434bdc98025f182cadac74e6a2a3cd0359f60.tar.gz binaryen-a7c434bdc98025f182cadac74e6a2a3cd0359f60.tar.bz2 binaryen-a7c434bdc98025f182cadac74e6a2a3cd0359f60.zip |
Improve return validation (#6551)
Disallow returns from having any children, even unreachable children, in
function that do not return any values.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/validator.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/gtest/validator.cpp b/test/gtest/validator.cpp index 87d698e56..99d5878ae 100644 --- a/test/gtest/validator.cpp +++ b/test/gtest/validator.cpp @@ -48,3 +48,20 @@ TEST(ValidatorTest, MissingCatchTag) { WasmValidator::FlagValues::Globally | WasmValidator::FlagValues::Quiet; EXPECT_FALSE(validator.validate(&function, module, flags)); } + +TEST(ValidatorTest, ReturnUnreachable) { + Module module; + Builder builder(module); + + // (return (unreachable)) should be invalid if a function has no return type. + auto func = + builder.makeFunction("func", + {}, + Signature(Type::none, Type::none), + {}, + builder.makeReturn(builder.makeUnreachable())); + + auto flags = + WasmValidator::FlagValues::Globally | WasmValidator::FlagValues::Quiet; + EXPECT_FALSE(WasmValidator{}.validate(func.get(), module, flags)); +} |