Coverage Report

Created: 2025-08-08 06:44

/src/WasmEdge/include/common/errcode.h
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
//===-- wasmedge/common/errcode.h - Error code definition -----------------===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the `Expected` wrappers.
12
///
13
//===----------------------------------------------------------------------===//
14
#pragma once
15
16
#include "common/enum_errcode.hpp"
17
#include "common/expected.h"
18
#include "common/hexstr.h"
19
#include "common/spdlog.h"
20
21
#include <cassert>
22
#include <ostream>
23
24
#if defined(_MSC_VER) && !defined(__clang__)
25
#define __builtin_unreachable() __assume(0)
26
#endif
27
28
#ifdef NDEBUG
29
#define assuming(R)                                                            \
30
2.07M
  (static_cast<bool>(R) ? static_cast<void>(0) : __builtin_unreachable())
31
0
#define assumingUnreachable() __builtin_unreachable()
32
#else
33
#define assuming(expr) assert(expr)
34
#define assumingUnreachable()                                                  \
35
  (assert(false && "unreachable"), __builtin_unreachable())
36
#endif
37
38
namespace WasmEdge {
39
40
64.1M
static inline constexpr bool likely(bool V) noexcept {
41
64.1M
  return __builtin_expect(V, true);
42
64.1M
}
Unexecuted instantiation: wasmedge.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: fuzzTool.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: fuzzPO.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: uniTool.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: compilerTool.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: runtimeTool.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: vm.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: plugin.cpp:WasmEdge::likely(bool)
module.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
61.7k
static inline constexpr bool likely(bool V) noexcept {
41
61.7k
  return __builtin_expect(V, true);
42
61.7k
}
Unexecuted instantiation: func.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: argument_parser.cpp:WasmEdge::likely(bool)
section.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
429k
static inline constexpr bool likely(bool V) noexcept {
41
429k
  return __builtin_expect(V, true);
42
429k
}
description.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
94.8k
static inline constexpr bool likely(bool V) noexcept {
41
94.8k
  return __builtin_expect(V, true);
42
94.8k
}
segment.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
109k
static inline constexpr bool likely(bool V) noexcept {
41
109k
  return __builtin_expect(V, true);
42
109k
}
type.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
104k
static inline constexpr bool likely(bool V) noexcept {
41
104k
  return __builtin_expect(V, true);
42
104k
}
Unexecuted instantiation: expression.cpp:WasmEdge::likely(bool)
instruction.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
29.2M
static inline constexpr bool likely(bool V) noexcept {
41
29.2M
  return __builtin_expect(V, true);
42
29.2M
}
loader.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
31.3k
static inline constexpr bool likely(bool V) noexcept {
41
31.3k
  return __builtin_expect(V, true);
42
31.3k
}
Unexecuted instantiation: component.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_section.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_instance.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_sort.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_alias.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_canonical.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_start.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_type.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_import.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_export.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_declarator.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_descriptor.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_valtype.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_module.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_section.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_segment.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_type.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_description.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_expression.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: serial_instruction.cpp:WasmEdge::likely(bool)
filemgr.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
14.2M
static inline constexpr bool likely(bool V) noexcept {
41
14.2M
  return __builtin_expect(V, true);
42
14.2M
}
Unexecuted instantiation: shared_library.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: aot_section.cpp:WasmEdge::likely(bool)
validator.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
8.34M
static inline constexpr bool likely(bool V) noexcept {
41
8.34M
  return __builtin_expect(V, true);
42
8.34M
}
Unexecuted instantiation: component_validator.cpp:WasmEdge::likely(bool)
formchecker.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
5.85M
static inline constexpr bool likely(bool V) noexcept {
41
5.85M
  return __builtin_expect(V, true);
42
5.85M
}
Unexecuted instantiation: proxy.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: threadInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: refInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: engine.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: helper.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: executor.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: coredump.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: component_canon.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: controlInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: tableInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: memoryInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: variableInstr.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: import.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: function.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: global.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: table.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: memory.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: elem.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: data.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: export.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: tag.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: environ.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: vinode.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: wasimodule.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: inode-linux.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: wasifunc.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: clock-linux.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: environ-linux.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: compiler.cpp:WasmEdge::likely(bool)
codegen.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
3.91k
static inline constexpr bool likely(bool V) noexcept {
41
3.91k
  return __builtin_expect(V, true);
42
3.91k
}
Unexecuted instantiation: jit.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: allocator.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: fault.cpp:WasmEdge::likely(bool)
Unexecuted instantiation: stacktrace.cpp:WasmEdge::likely(bool)
hash.cpp:WasmEdge::likely(bool)
Line
Count
Source
40
5.62M
static inline constexpr bool likely(bool V) noexcept {
41
5.62M
  return __builtin_expect(V, true);
42
5.62M
}
Unexecuted instantiation: errinfo.cpp:WasmEdge::likely(bool)
43
35.9M
static inline constexpr bool unlikely(bool V) noexcept {
44
35.9M
  return __builtin_expect(V, false);
45
35.9M
}
Unexecuted instantiation: wasmedge.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: fuzzTool.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: fuzzPO.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: uniTool.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: compilerTool.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: runtimeTool.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: vm.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: plugin.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: module.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: func.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: argument_parser.cpp:WasmEdge::unlikely(bool)
section.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
105k
static inline constexpr bool unlikely(bool V) noexcept {
44
105k
  return __builtin_expect(V, false);
45
105k
}
description.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
666
static inline constexpr bool unlikely(bool V) noexcept {
44
666
  return __builtin_expect(V, false);
45
666
}
segment.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
7.96k
static inline constexpr bool unlikely(bool V) noexcept {
44
7.96k
  return __builtin_expect(V, false);
45
7.96k
}
type.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
94.0k
static inline constexpr bool unlikely(bool V) noexcept {
44
94.0k
  return __builtin_expect(V, false);
45
94.0k
}
Unexecuted instantiation: expression.cpp:WasmEdge::unlikely(bool)
instruction.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
8.62M
static inline constexpr bool unlikely(bool V) noexcept {
44
8.62M
  return __builtin_expect(V, false);
45
8.62M
}
Unexecuted instantiation: loader.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_section.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_instance.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_sort.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_alias.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_canonical.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_start.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_type.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_import.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_export.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_declarator.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_descriptor.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_valtype.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_module.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_section.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_segment.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_type.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_description.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_expression.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: serial_instruction.cpp:WasmEdge::unlikely(bool)
filemgr.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
27.0M
static inline constexpr bool unlikely(bool V) noexcept {
44
27.0M
  return __builtin_expect(V, false);
45
27.0M
}
Unexecuted instantiation: shared_library.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: aot_section.cpp:WasmEdge::unlikely(bool)
validator.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
5.66k
static inline constexpr bool unlikely(bool V) noexcept {
44
5.66k
  return __builtin_expect(V, false);
45
5.66k
}
Unexecuted instantiation: component_validator.cpp:WasmEdge::unlikely(bool)
formchecker.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
5.39k
static inline constexpr bool unlikely(bool V) noexcept {
44
5.39k
  return __builtin_expect(V, false);
45
5.39k
}
Unexecuted instantiation: proxy.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: threadInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: refInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: engine.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: helper.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: executor.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: coredump.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: component_canon.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: controlInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: tableInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: memoryInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: variableInstr.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: import.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: function.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: global.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: table.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: memory.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: elem.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: data.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: export.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: tag.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: environ.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: vinode.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: wasimodule.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: inode-linux.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: wasifunc.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: clock-linux.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: environ-linux.cpp:WasmEdge::unlikely(bool)
compiler.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
1.95k
static inline constexpr bool unlikely(bool V) noexcept {
44
1.95k
  return __builtin_expect(V, false);
45
1.95k
}
codegen.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
30.9k
static inline constexpr bool unlikely(bool V) noexcept {
44
30.9k
  return __builtin_expect(V, false);
45
30.9k
}
Unexecuted instantiation: jit.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: allocator.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: fault.cpp:WasmEdge::unlikely(bool)
Unexecuted instantiation: stacktrace.cpp:WasmEdge::unlikely(bool)
hash.cpp:WasmEdge::unlikely(bool)
Line
Count
Source
43
32.3k
static inline constexpr bool unlikely(bool V) noexcept {
44
32.3k
  return __builtin_expect(V, false);
45
32.3k
}
Unexecuted instantiation: errinfo.cpp:WasmEdge::unlikely(bool)
46
47
/// Type aliasing for Expected<T, ErrCode>.
48
template <typename T> using Expect = Expected<T, ErrCode>;
49
50
/// Helper function for Unexpected<ErrCode>.
51
4.65k
constexpr auto Unexpect(const ErrCode &Val) { return Unexpected<ErrCode>(Val); }
52
7.84k
template <typename... ArgsT> constexpr auto Unexpect(ArgsT... Args) {
53
7.84k
  return Unexpected<ErrCode>(ErrCode(Args...));
54
7.84k
}
auto WasmEdge::Unexpect<WasmEdge::ErrCode::Value>(WasmEdge::ErrCode::Value)
Line
Count
Source
52
7.84k
template <typename... ArgsT> constexpr auto Unexpect(ArgsT... Args) {
53
7.84k
  return Unexpected<ErrCode>(ErrCode(Args...));
54
7.84k
}
Unexecuted instantiation: auto WasmEdge::Unexpect<WasmEdge::ErrCategory, unsigned int>(WasmEdge::ErrCategory, unsigned int)
55
0
template <typename T> constexpr auto Unexpect(const Expect<T> &Val) {
56
0
  return Unexpected<ErrCode>(Val.error());
57
0
}
58
59
} // namespace WasmEdge
60
61
template <>
62
struct fmt::formatter<WasmEdge::ErrCode> : fmt::formatter<std::string_view> {
63
  fmt::format_context::iterator
64
  format(const WasmEdge::ErrCode &Code,
65
0
         fmt::format_context &Ctx) const noexcept {
66
0
    using namespace std::literals;
67
0
    std::string Output =
68
0
        fmt::format("{} failed: {}, Code: 0x{:03x}"sv, Code.getErrCodePhase(),
69
0
                    WasmEdge::ErrCodeStr[Code.getEnum()], Code.getCode());
70
0
    return formatter<std::string_view>::format(Output, Ctx);
71
0
  }
72
};
73
74
template <>
75
struct fmt::formatter<WasmEdge::ErrCode::Value>
76
    : fmt::formatter<WasmEdge::ErrCode> {
77
  fmt::format_context::iterator
78
  format(const WasmEdge::ErrCode::Value &Value,
79
0
         fmt::format_context &Ctx) const noexcept {
80
0
    return formatter<WasmEdge::ErrCode>::format(WasmEdge::ErrCode(Value), Ctx);
81
0
  }
82
};