GNOME Bugzilla – Bug 570091
[feb 1st trunk valac] compile gives segv in vala_data_type_get_cnam
Last modified: 2009-06-06 15:20:58 UTC
Steps to reproduce: 1. run make on this testcase (feel free to use snippet as regression test later) 2. segv in valac inside vala_data_type_get_cnam vala 0.5.1 does NOT exhibit this bug vala 0.5.4 DOES exhibit this bug vala 0.5.3 DOES exhibit this bug vala 0.5.2 DOES exhibit this bug vala 0.4.0 does NOT exhibit this bug Details here: https://bugs.launchpad.net/ubuntu/+source/vala/+bug/323943 These asserts are hit inside valac: ** (valac:15783): CRITICAL **: vala_ccode_base_module_get_temp_variable: assertion `type != NULL' failed ** (valac:15783): CRITICAL **: vala_symbol_get_name: assertion `self != NULL' failed ** (valac:15783): CRITICAL **: vala_ccode_base_module_get_variable_cexpression: assertion `name != NULL' failed ** (valac:15783): CRITICAL **: vala_ccode_assignment_construct: assertion `l != NULL' failed ** (valac:15783): CRITICAL **: vala_ccode_comma_expression_append_expression: assertion `expr != NULL' failed ** (valac:15783): CRITICAL **: vala_symbol_get_name: assertion `self != NULL' failed ** (valac:15783): CRITICAL **: vala_ccode_base_module_get_variable_cexpression: assertion `name != NULL' failed ** (valac:15783): CRITICAL **: vala_ccode_comma_expression_append_expression: assertion `expr != NULL' failed ** (valac:15783): CRITICAL **: vala_local_variable_get_variable_type: assertion `self != NULL' failed make: *** [all] Segmentation fault (core dumped) Here is the stack (captured with Feb 1st trunk valac):
+ Trace 212091
Stack trace: Other information:
Created attachment 127699 [details] testcase
Reduced test case: public class Stack<T> { public T peek () throws Error { return null; } } public static void main (string[] args) { Stack<string> st = new Stack<string> (); while (st.peek ()) { } }
Created attachment 131517 [details] [review] Patch Moves conditional split farther up the analysis tree for loop conditions, preventing recursing into partially-completed analysis when conditional expressions can throw errors.
Thanks for the patch. Unfortunately, removing the code that handles method calls that can throw errors can lead to incorrect code. For example, if you assign the result of a method call to a local variable, the compiler will not catch the error until after the assignment if your patch is applied. However, the assignment must not happen in the error case.
Created attachment 132792 [details] [review] Patch Reworked patch.
Thanks for the updated patch. It still causes some regressions. For example, the following test case results in an endless loop with your patch applied: public class Stack<T> { static int i = 0; public bool peek () throws Error { return (i++ == 0); } } public static void main (string[] args) { Stack<string> st = new Stack<string> (); while (st.peek ()) { } }
Created attachment 134563 [details] [review] Patch Reworked again per comments.
Thanks for the update. The patch goes into the right direction by doing the transformation earlier. To avoid similar issues in the future, I'll take the patch a step further and transform all while, do, and for loops into one simple loop type without a condition. This simplifies code in semantic and flow analysis and code generation.
commit fef10859ae29c524cac6a7388759f02e26df160d Author: Jürg Billeter <j@bitron.ch> Date: Sat Jun 6 17:04:02 2009 +0200 Convert for loops into simple loops commit a71e6e0dea67455e741ffe319f796419a3fa42fe Author: Jürg Billeter <j@bitron.ch> Date: Sat Jun 6 16:20:32 2009 +0200 Convert do loops into simple loops commit 14cb3893cf381f6b9136eccccdba86bc42786a56 Author: Jürg Billeter <j@bitron.ch> Date: Sat Jun 6 15:58:44 2009 +0200 Convert while loops into simple loops Simplifies and fixes bugs in semantic and flow analysis and code generation. Based on patch by Levi Bard, fixes bug 570091.