GNOME Bugzilla – Bug 744639
Cannot compile code genereated by vala with clang -Werror=return-type
Last modified: 2015-02-24 15:52:01 UTC
This problem currently causes error when compiling anjuta. There is a simple vala code to reproduce the issue: int main () { Thread.create<void>(() => {}, false); return 0; } Valac converts it to: /* simplethread.c generated by valac 0.27.1.11-4ffca0, the Vala compiler * generated from simplethread.vala, do not modify */ #include <glib.h> #include <glib-object.h> gint _vala_main (void); static void __lambda4_ (void); static gpointer ___lambda4__gthread_func (gpointer self); static void __lambda4_ (void) { } static gpointer ___lambda4__gthread_func (gpointer self) { __lambda4_ (); } gint _vala_main (void) { gint result = 0; GError * _inner_error_ = NULL; g_thread_create (___lambda4__gthread_func, NULL, FALSE, &_inner_error_); if (G_UNLIKELY (_inner_error_ != NULL)) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return 0; } result = 0; return result; } int main (int argc, char ** argv) { #if !GLIB_CHECK_VERSION (2,35,0) g_type_init (); #endif return _vala_main (); } The problem is that ___lambda4__gthread_func doesn't have a return value, which causes clang -Werror=return-type to fail: error: control reaches end of non-void function [-Werror,-Wreturn-type]
As a general rule of thumb it's better not to compile Vala code with C compilers warnings enabled. While warnings tend to be very use for programmers they are often less so when autogenerating code as compiler should opt out for its simplicity and obvious correctness rather then simplicity and obviousness of generated code. For example it allows to unroll each function call into assignment to temporary variables regardless if the value is used later or not. However the generated code may be incorrect per 6.9.1.12 depending on g_thread_create implementation (or other function receiving the closure) so it should be fixed as Vala produce incorrect C code (i.e. one containing UB).
Yes we should return a default value there. Thanks.
Created attachment 297758 [details] [review] codegen: return default value in delegate wrappers Does the attached patch fix your problem?
Yes, it fixes the problem. Thanks.
commit 9850121b6c3fe8c3a0fce3bc121c05483c5a1739 Author: Luca Bruno <lucabru@src.gnome.org> Date: Tue Feb 24 13:47:12 2015 +0100 codegen: Return a default value in delegate wrappers Fixes bug 744639 This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version. After your distribution has provided you with the updated package - and if you have some time - please feel encouraged to verify the fix by changing the status of this bug report to VERIFIED. If the updated package does not fix the reported issue, please reopen this bug report.