-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
wasm2c: fix not all control paths return a value warning #24206
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
base: master
Are you sure you want to change the base?
Conversation
I think adding a |
Well, adding "noreturn" to the panic declaration not only fixes this warning, but, also improves all the other places panic is called by letting the compiler know it doesn't return, which gives the compiler/optimize more accurate information. That seems like a win/win to me? I'm not seeing a downside? |
We have a policy of keeping the |
b915073
to
9e5bf1b
Compare
I see. I think I can work with that. I just inlined the body of the custom |
I got the following warning when compiling zig-wasm2c: C:\git\zig\stage1\wasm.h(55) : warning C4715: 'WasmMut_toC': not all control paths return a value This is because the C compiler doesn't understand that the panic function from `panic.h` is noreturn. I addressed this making panic a macro so the caller sees that abort is called and is able to see that it's a "noreturn codepath".
9e5bf1b
to
52d0bed
Compare
Ooo nevermind, I think I came up with something better. I changed |
But you're still relying on the compiler being able to figure out that |
We're not relying on the compiler to know that abort is noreturn for the program to behave correctly. It's an extra piece of information that the compiler/optimizer can use to eliminate dead branches (and erroneous warnings). |
An optimizer that understands noreturn already understands that a function that calls noreturn functions on every path is also noreturn. The attribute exists so that the optimizer knows whether external functions that it can't analyze are noreturn. Also this program compiles and runs in 0m0.725s, it does not need optimizations at this time. |
I got the following warning when compiling zig-wasm2c:
This is because the C compiler doesn't understand that the panic function from
panic.h
is noreturn. I addressed this copying the body of the panic function into the call-site directly which is just a printf and abort. Now the compiler knows the codepath afterwards is unreachable because abort has the proper function decorators to mark it noreturn.