* try_finally_expr in must_not_throw_expr
@ 2022-07-31 14:25 Philipp Rimmele
2022-08-02 12:23 ` Richard Sandiford
0 siblings, 1 reply; 2+ messages in thread
From: Philipp Rimmele @ 2022-07-31 14:25 UTC (permalink / raw)
To: gcc
Hi,
i'm developing a GCC-Plugin. And i don't understand why there is a "try_finally_expr" in a must_not_throw-Area in my AST. It happens in the destructors.
Here is my AST:
function_decl Exception::__dt_base
1: must_not_throw_expr(->void_type{void})[42]
0: statement_list(->void_type{void})
0: bind_expr(->void_type{void})[42]
1: statement_list(->void_type{void})
0: cleanup_point_expr(->void_type{void})[42]
0: expr_stmt(->void_type{void})
0: convert_expr(->void_type{void})
0: modify_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
0: component_ref(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
0: indirect_ref(->record_type{Exception})
0: nop_expr(->pointer_type->record_type{Exception})
0: parm_decl(->pointer_type->record_type{Exception}) : this
1: field_decl(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
1: pointer_plus_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
0: addr_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
0: var_decl(->array_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int}) : _ZTV9Exception
1: integer_cst : 16 : 1
0: try_finally(->void_type{void})[42]
0: statement_list(->void_type{void})
1: modify_expr(->void_type{void})
0: indirect_ref(->record_type)
0: nop_expr(->reference_type->record_type)
0: parm_decl(->pointer_type->record_type{Exception}) : this
1: constructor(->record_type)
2: block
0: label_expr(->void_type{void})[42]
0: label_decl(->void_type{void}) : <unnamed>
What is the reason for this? There should no Exception be thrown, so why handle it with a try_finally-Expression? I'm currently using GCC-8.2.0.
I would be realy glad if you could answer me this question. And if you can give me some examples, where the try_finally-expression is also used, it would be realy helpfull.
Thank you and kind regards,
Philipp Rimmele
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: try_finally_expr in must_not_throw_expr
2022-07-31 14:25 try_finally_expr in must_not_throw_expr Philipp Rimmele
@ 2022-08-02 12:23 ` Richard Sandiford
0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2022-08-02 12:23 UTC (permalink / raw)
To: Philipp Rimmele via Gcc; +Cc: Philipp Rimmele
Philipp Rimmele via Gcc <gcc@gcc.gnu.org> writes:
> Hi,
>
> i'm developing a GCC-Plugin. And i don't understand why there is a "try_finally_expr" in a must_not_throw-Area in my AST. It happens in the destructors.
> Here is my AST:
> function_decl Exception::__dt_base
> 1: must_not_throw_expr(->void_type{void})[42]
> 0: statement_list(->void_type{void})
> 0: bind_expr(->void_type{void})[42]
> 1: statement_list(->void_type{void})
> 0: cleanup_point_expr(->void_type{void})[42]
> 0: expr_stmt(->void_type{void})
> 0: convert_expr(->void_type{void})
> 0: modify_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
> 0: component_ref(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
> 0: indirect_ref(->record_type{Exception})
> 0: nop_expr(->pointer_type->record_type{Exception})
> 0: parm_decl(->pointer_type->record_type{Exception}) : this
> 1: field_decl(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
> 1: pointer_plus_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
> 0: addr_expr(->pointer_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int})
> 0: var_decl(->array_type->pointer_type{__vtbl_ptr_type}->function_type->integer_type{int}) : _ZTV9Exception
> 1: integer_cst : 16 : 1
> 0: try_finally(->void_type{void})[42]
> 0: statement_list(->void_type{void})
> 1: modify_expr(->void_type{void})
> 0: indirect_ref(->record_type)
> 0: nop_expr(->reference_type->record_type)
> 0: parm_decl(->pointer_type->record_type{Exception}) : this
> 1: constructor(->record_type)
> 2: block
> 0: label_expr(->void_type{void})[42]
> 0: label_decl(->void_type{void}) : <unnamed>
>
> What is the reason for this? There should no Exception be thrown, so why handle it with a try_finally-Expression? I'm currently using GCC-8.2.0.
> I would be realy glad if you could answer me this question. And if you can give me some examples, where the try_finally-expression is also used, it would be realy helpfull.
I'm not an expert on this by any means, but since no-one else has
replied yet... I suspect it's simpler to use try_finally whenever
something needs to be run at the end of a scope, regardless of whether
the scope ends through fallthrough, breaking, continuing, or exceptions.
To put it another way: try_finally at this stage doesn't guarantee
that exception handling will actually be needed. For example:
try
{
int i = 1;
int j = 2;
if (i == j)
foo ();
}
finally ...
starts out with a potentially-throwing call to foo, but it (and the
possibility of an exception) will get optimised away later. It probably
didn't seem worthwhile having the frontend do a similar but separate
analysis of whether statements might throw.
Thanks,
Richard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-02 12:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 14:25 try_finally_expr in must_not_throw_expr Philipp Rimmele
2022-08-02 12:23 ` Richard Sandiford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).