Skip to content

Fix build with GCC. #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const int iterations = 100000;

void finalize(void* data) {
int i = (int)data;
int i = (intptr_t)data;
if (i % (iterations / 10) == 0) printf("Finalizing #%d...\n", i);
}

Expand Down
6 changes: 3 additions & 3 deletions src/wasm-bin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void encode_const_zero(char*& ptr, const ValType* type) {
case F64: *ptr++ = 0x44; break;
default: assert(false);
}
for (int i = 0; i < zero_size(type); ++i) *ptr++ = 0;
for (size_t i = 0; i < zero_size(type); ++i) *ptr++ = 0;
}


Expand Down Expand Up @@ -123,7 +123,7 @@ auto wrapper(const FuncType* type) -> vec<byte_t> {
*ptr++ = 0x00; // func
*ptr++ = 0; // func index

assert(ptr - binary.get() == size);
assert(static_cast<size_t>(ptr - binary.get()) == size);
return binary;
}

Expand All @@ -149,7 +149,7 @@ auto wrapper(const GlobalType* type) -> vec<byte_t> {
*ptr++ = 0x03; // global
*ptr++ = 0; // func index

assert(ptr - binary.get() == size);
assert(static_cast<size_t>(ptr - binary.get()) == size);
return binary;
}

Expand Down
6 changes: 5 additions & 1 deletion src/wasm-v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ auto ExternType::copy() const -> own<ExternType*> {
case EXTERN_GLOBAL: return global()->copy();
case EXTERN_TABLE: return table()->copy();
case EXTERN_MEMORY: return memory()->copy();
default: assert(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wouldn't having a branch with no return trip up other compilers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily enough, I've added all those asserts (with the exception of the one in src/wasm-v8.cc:2199, which I added for completeness) to silence the no return errors in GCC:

error: control reaches end of non-void function [-Werror=return-type]

so this works fine for both: clang and gcc, at least using default CFLAGS.

But now that you pointed this out, I realized that this will indeed break when building with -DNDEBUG (i.e. when assert() is omitted), but this is already the case in master, since the same pattern is used in a few other places, e.g. in src/wasm-bin.cc:220:

assert(false);

Perhaps all those assert(false) should be replaced with UNIMPLEMENTED()? What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, though I don't think we want to abuse UNIMPLEMENTED, but define a similar UNREACHABLE. Do you mind including that with this PR?

}
}

Expand Down Expand Up @@ -1100,6 +1101,7 @@ auto v8_to_val(
UNIMPLEMENTED("ref value");
}
}
default: assert(false);
}
}

Expand Down Expand Up @@ -1550,6 +1552,7 @@ auto Extern::type() const -> own<ExternType*> {
case EXTERN_GLOBAL: return global()->type();
case EXTERN_TABLE: return table()->type();
case EXTERN_MEMORY: return memory()->type();
default: assert(false);
}
}

Expand Down Expand Up @@ -1794,7 +1797,7 @@ void FuncData::v8_callback(const v8::FunctionCallbackInfo<v8::Value>& info) {
auto& param_types = self->type->params();
auto& result_types = self->type->results();

assert(param_types.size() == info.Length());
assert(param_types.size() == static_cast<size_t>(info.Length()));

// TODO: cache params and result arrays per thread.
auto args = std::unique_ptr<Val[]>(new Val[param_types.size()]);
Expand Down Expand Up @@ -2194,6 +2197,7 @@ auto Instance::exports() const -> vec<Extern*> {
assert(wasm_v8::extern_kind(obj) == wasm_v8::EXTERN_MEMORY);
exports[i].reset(RefImpl<Memory>::make(store, obj));
} break;
default: assert(false);
}
}

Expand Down