-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from wasmx/parser_no_default_case
Introduce UNREACHABLE macro
- Loading branch information
Showing
8 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2020 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "asserts.hpp" | ||
|
||
#ifdef GCOV | ||
extern "C" void __gcov_flush(); | ||
#endif | ||
|
||
namespace fizzy | ||
{ | ||
bool unreachable() noexcept | ||
{ | ||
#ifdef GCOV | ||
__gcov_flush(); | ||
#endif | ||
return false; // LCOV_EXCL_LINE | ||
} | ||
} // namespace fizzy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2020 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <cassert> | ||
|
||
#ifndef __has_builtin | ||
#define __has_builtin(name) 0 | ||
#endif | ||
|
||
#ifndef __has_feature | ||
#define __has_feature(name) 0 | ||
#endif | ||
|
||
|
||
namespace fizzy | ||
{ | ||
/// A helper for assert(unreachable()). Always returns false. Also flushes coverage data. | ||
bool unreachable() noexcept; | ||
} // namespace fizzy | ||
|
||
#ifndef NDEBUG | ||
#define FIZZY_UNREACHABLE() assert(fizzy::unreachable()) | ||
#elif __has_builtin(__builtin_unreachable) | ||
#define FIZZY_UNREACHABLE() __builtin_unreachable() | ||
#else | ||
#define FIZZY_UNREACHABLE() (void)0 | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2020 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "asserts.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
#if !defined(NDEBUG) || __has_feature(undefined_behavior_sanitizer) | ||
TEST(asserts_death, unreachable) | ||
{ | ||
static constexpr auto unreachable = []() noexcept { FIZZY_UNREACHABLE(); }; | ||
EXPECT_DEATH(unreachable(), "unreachable"); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Fizzy: A fast WebAssembly interpreter | ||
// Copyright 2020 The Fizzy Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "asserts.hpp" | ||
#include "execute.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace fizzy; | ||
|
||
#if !defined(NDEBUG) || __has_feature(undefined_behavior_sanitizer) | ||
TEST(execute_death, malformed_instruction_opcode) | ||
{ | ||
constexpr auto malformed_opcode = static_cast<Instr>(6); | ||
|
||
Code code; | ||
code.instructions.emplace_back(malformed_opcode); | ||
code.instructions.emplace_back(Instr::end); | ||
|
||
auto module = std::make_unique<Module>(); | ||
module->typesec.emplace_back(FuncType{}); | ||
module->funcsec.emplace_back(TypeIdx{0}); | ||
module->codesec.emplace_back(std::move(code)); | ||
|
||
auto instance = instantiate(std::move(module)); | ||
EXPECT_DEATH(execute(*instance, 0, nullptr), "unreachable"); | ||
} | ||
#endif |