Commit ff7bf332 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Avoid reporting of unrelated compiler errors

It happens frequently that unrelated compiler errors lead to the
instantiation of {read_leb_tail} with an invalid {byte_index}, which
again triggers compiler errors.
This change fixes this, such that illegal instantiation just triggers a
static_assert and nothing more. This helps to spot the actual error.

Drive-by: Mark {Min} and {Max} constexpr, such that they can produce
constexpr results. Note that the result will only be constexpr if both
arguments are constexpr.

R=ahaas@chromium.org

Change-Id: I35d6865a7f569d72ace0debb045ac615cfd87d92
Reviewed-on: https://chromium-review.googlesource.com/518005Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45558}
parent 68aa1ab3
......@@ -188,14 +188,14 @@ inline bool IsAddressAligned(Address addr,
// Returns the maximum of the two parameters.
template <typename T>
T Max(T a, T b) {
constexpr T Max(T a, T b) {
return a < b ? b : a;
}
// Returns the minimum of the two parameters.
template <typename T>
T Min(T a, T b) {
constexpr T Min(T a, T b) {
return a < b ? a : b;
}
......
......@@ -344,7 +344,7 @@ class Decoder {
}
}
constexpr int sign_ext_shift =
is_signed && !is_last_byte ? 8 * sizeof(IntType) - shift - 7 : 0;
is_signed ? Max(0, int{8 * sizeof(IntType)} - shift - 7) : 0;
// Perform sign extension.
result = (result << sign_ext_shift) >> sign_ext_shift;
if (trace && is_signed) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment