diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-02-06 18:52:11 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-02-06 19:06:01 +0100 |
commit | 6dec23dc1c5b8567d0e2eddeab226e5cbd817cdc (patch) | |
tree | e313bc7bee6a920c3af642c685196002b4db8f87 | |
parent | 0771248fd47770e0d25d139143de41eb16a6ee07 (diff) | |
download | vala-6dec23dc1c5b8567d0e2eddeab226e5cbd817cdc.tar.gz |
vala: Better handling of [NoReturn] call inside finally clause
This caused the following criticals:
vala_flow_analyzer_jump_target_construct_finally_clause: assertion 'last_block != NULL' failed
vala_flow_analyzer_jump_target_get_is_exit_target: assertion 'self != NULL' failed
vala_flow_analyzer_jump_target_get_is_error_target: assertion 'self != NULL' failed
vala_flow_analyzer_jump_target_get_is_finally_clause: assertion 'self != NULL' failed
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/control-flow/finally-no-return.c-expected | 59 | ||||
-rw-r--r-- | tests/control-flow/finally-no-return.vala | 14 | ||||
-rw-r--r-- | vala/valaflowanalyzer.vala | 4 |
4 files changed, 77 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 518b892a9..9257e61ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -296,6 +296,7 @@ TESTS = \ control-flow/continue-invalid.test \ control-flow/double-catch.test \ control-flow/expressions-conditional.vala \ + control-flow/finally-no-return.vala \ control-flow/finally-return.test \ control-flow/for.vala \ control-flow/for-switch-continue.vala \ diff --git a/tests/control-flow/finally-no-return.c-expected b/tests/control-flow/finally-no-return.c-expected new file mode 100644 index 000000000..732c8bcde --- /dev/null +++ b/tests/control-flow/finally-no-return.c-expected @@ -0,0 +1,59 @@ +/* control_flow_finally_no_return.c generated by valac, the Vala compiler + * generated from control_flow_finally_no_return.vala, do not modify */ + +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_WIN32) || defined(__CYGWIN__) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +VALA_EXTERN void foo (GError** error); +VALA_EXTERN void bar (void); +static void _vala_main (void); + +void +foo (GError** error) +{ +} + +void +bar (void) +{ +} + +static void +_vala_main (void) +{ + GError* _inner_error0_ = NULL; + { + foo (&_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __finally0; + } + } + __finally0: + { + GError* _inner_error1_ = NULL; + bar (); + } + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/control-flow/finally-no-return.vala b/tests/control-flow/finally-no-return.vala new file mode 100644 index 000000000..285112a3a --- /dev/null +++ b/tests/control-flow/finally-no-return.vala @@ -0,0 +1,14 @@ +void foo () throws Error { +} + +[NoReturn] +void bar () { +} + +void main () { + try { + foo (); + } finally { + bar (); + } +} diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index 9c9457fd5..45f524546 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -1018,7 +1018,9 @@ public class Vala.FlowAnalyzer : CodeVisitor { return; } - jump_stack.add (new JumpTarget.finally_clause (finally_block, current_block)); + if (current_block != null) { + jump_stack.add (new JumpTarget.finally_clause (finally_block, current_block)); + } } int finally_jump_stack_size = jump_stack.size; |