This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: try_finally_expr wrong source location info


Hello,

>> But then, after lowering on the eh pass (gcc/tree-eh.c:1161), the "finally"
>> location is set up to the `gimple_location (tf->try_finally_expr)' which
>> actually expands to "testcase.cxx:4", a place where the "try" block starts.
>>
>> The dump testcase.cxx.009t.ehopt shows no location info for destructor:
>>  std::unique_ptr<char>::~unique_ptr (&lang);
>>
>> And next testcase.cxx.010t.eh dump shows equal location for constructor and
>> destructor:
>>  [testcase.cxx:4:38] std::unique_ptr<char>::unique_ptr ([testcase.cxx:4:38]
>> &lang, D.42272); [testcase.cxx:4:38] std::unique_ptr<char>::~unique_ptr
>> (&lang);
>>
>> I performed several experiments trying to get information about gimple_block
>> around the try_finally_expr statement right in `lower_try_finally_onedest',
>> but unsuccessfully. And also, as far as I understand, this issue should be
>> fixed in all the lowering functions, not only this one.
>>
>> Where should I dig in order to fix the issue?
>
> We have been using this patchlet locally for some time:
>
> Index: tree-eh.c
> ===================================================================
> --- tree-eh.c   (revision 248944)
> +++ tree-eh.c   (working copy)
> @@ -1413,11 +1413,12 @@ lower_try_finally_switch (struct leh_sta
>        x = gimple_build_assign (finally_tmp,
>                                build_int_cst (integer_type_node,
>                                               fallthru_index));
> +      gimple_set_location (x, finally_loc);
>        gimple_seq_add_stmt (&tf->top_p_seq, x);
>
>        tmp = build_int_cst (integer_type_node, fallthru_index);
>        last_case = build_case_label (tmp, NULL,
> -                                   create_artificial_label (tf_loc));
> +                                   create_artificial_label (finally_loc));
>        case_label_vec.quick_push (last_case);
>        last_case_index++;
>
> @@ -1426,7 +1427,7 @@ lower_try_finally_switch (struct leh_sta
>
>        tmp = lower_try_finally_fallthru_label (tf);
>        x = gimple_build_goto (tmp);
> -      gimple_set_location (x, tf_loc);
> +      gimple_set_location (x, finally_loc);
>        gimple_seq_add_stmt (&switch_body, x);
>      }

I tried the patch, but it has no effect since `lower_try_finally_switch' is not
used in automatically generated destructors (at least for `unique_ptr'), the
`lower_try_finally_onedest' is used and it seems that the is no straightforward
way to generate `finally_loc' in like of the one you use in the patch.

It seems that the best solution here will be to find the end of scope where the
object is created but I still can't implement the method to extract this info.
gimple_block() does not provide this info, and accordingly to GCC online docs
it shouldn't:
> the C++ front end uses pseudo-scopes to handle cleanups for objects with
> destructors, these don’t translate into the GIMPLE form

The best thing I could achieve is to set `finally' source location equal to the
previous statement. Now my report shows to the last line in function, which is
much better than blaming constructor, but still not the result I wanted to get;
this might be confusing when last line is some kind of resource freeing
function call.

Best Regards,
Vyacheslav Barinov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]