@@ -583,11 +583,14 @@ static an_expr_node_ptr make_call_node_full(
583583 an_expr_node_ptr arg_list,
584584 an_expr_node_ptr return_value,
585585 a_boolean is_virtual_call,
586- an_insert_location *insert_location)
586+ an_insert_location *insert_location,
587+ a_source_position *call_position)
587588/*
588589Make an expression that calls routine "routine" with arguments "arg_list",
589590and return a pointer to it (or to the assignment expression generated if
590591return_value is non-NULL). arg_list is assumed to be lowered already.
592+ If call_position is non-NULL, it is recorded as the position of the call
593+ node (otherwise, the call node has no position).
591594If return_value is non-NULL, it represents an lvalue to which the return
592595value from the call operation will be assigned (otherwise any value returned
593596by the call is ignored). If insert_location is not NULL, an expression
@@ -634,6 +637,7 @@ either make_call_node or make_call_statement is preferred when possible.
634637 rout_return_type = lowered_return_type_of(routine->type);
635638 call_node = make_operator_node((an_expr_operator_kind)eok_call,
636639 rout_return_type, rout_node);
640+ if (call_position != NULL) call_node->position = *call_position;
637641 /* If the caller requested that the return value from the call be
638642 assigned to an lvalue expression, create the assignment expression. */
639643 if (return_value != NULL) {
@@ -680,7 +684,8 @@ will be attempted.
680684
681685 call_node = make_call_node_full(routine, arg_list, (an_expr_node_ptr)NULL,
682686 /*is_virtual_call=*/FALSE,
683- (an_insert_location *)NULL);
687+ (an_insert_location *)NULL,
688+ (a_source_position *)NULL);
684689 check_assertion(call_node != NULL);
685690 return call_node;
686691} /* make_call_node */
@@ -698,7 +703,8 @@ of the call is assigned.
698703*/
699704{
700705 (void)make_call_node_full(routine, arg_list, return_value,
701- /*is_virtual_call=*/FALSE, insert_location);
706+ /*is_virtual_call=*/FALSE, insert_location,
707+ (a_source_position *)NULL);
702708} /* make_call_statement */
703709
704710
@@ -5906,15 +5912,18 @@ static void add_destructor_call(
59065912 an_init_pos_descr_ptr ipdp,
59075913 a_boolean have_complete_object,
59085914 ARG_UNUSED an_expr_node_ptr vtt_addr_node,
5909- an_insert_location_ptr insert_location)
5915+ an_insert_location_ptr insert_location,
5916+ a_source_position *call_position)
59105917/*
59115918Make a call statement that invokes the destructor dtor_routine for
59125919the entity whose position is given by ipdp. If the entity is a whole array,
59135920destroy all the elements. have_complete_object is TRUE if the
59145921entity is a complete object. vtt_addr_node is an expression for the virtual
59155922table table address that should be passed to the base class destructor
59165923(IA-64 ABI only), or NULL if one is not needed. Insert the statement
5917- at *insert_location and update *insert_location. The call generated
5924+ at *insert_location and update *insert_location. If call_position is
5925+ non-NULL, it is recorded as the position of the call expression (the
5926+ statement gets code_pos_for_lowering regardless). The call generated
59185927is not a virtual call even if the destructor is virtual. Note: this
59195928routine takes separate dtor_routine and ipdp parameters instead of a
59205929dynamic init pointer because of the make_destruction_routine case.
@@ -5953,6 +5962,7 @@ dynamic init pointer because of the make_destruction_routine case.
59535962 call_node = make_vec_delete_call(entity_node, num_elem_node,
59545963 dtor_addr_node, (a_routine *)NULL,
59555964 /*free_storage=*/FALSE);
5965+ if (call_position != NULL) call_node->position = *call_position;
59565966 /* Make a statement containing the call and insert it at the right
59575967 location. */
59585968 (void)insert_expr_statement_set_pos(call_node, insert_location);
@@ -5979,10 +5989,12 @@ dynamic init pointer because of the make_destruction_routine case.
59795989 }
59805990#endif /* !IA64_ABI */
59815991 entity_node->next = implied_arg_list;
5982- /* Make and insert an expression statement containing the call
5983- expression. */
5984- make_call_statement(dtor_routine, entity_node, (an_expr_node_ptr)NULL,
5985- insert_location);
5992+ /* Make the call expression and (because insert_location is non-NULL)
5993+ insert an expression statement containing it. */
5994+ (void)make_call_node_full(dtor_routine, entity_node,
5995+ (an_expr_node_ptr)NULL,
5996+ /*is_virtual_call=*/FALSE, insert_location,
5997+ call_position);
59865998 } /* if */
59875999} /* add_destructor_call */
59886000
@@ -6029,9 +6041,22 @@ and not for constructor_init entries in destructors.
60296041 a_destructible_entity_descr_ptr dedp = dip->destructible_entity_descr;
60306042 an_insert_location insert_location2;
60316043 an_insert_location_ptr effective_insert_loc;
6044+ a_source_position saved_error_position;
6045+ a_source_position *call_position = NULL;
60326046
60336047 check_assertion(dedp != NULL);
60346048 check_assertion(dip->destructor != NULL);
6049+ saved_error_position = error_position;
6050+ if (dip->variable != NULL &&
6051+ dip->variable->source_corresp.decl_position.seq != 0) {
6052+ /* The generated code is attributed to the point of destruction (e.g.,
6053+ the closing brace of a block; see code_pos_for_lowering), but
6054+ diagnostics about the destruction are attributed to the declaration
6055+ of the destroyed variable, which is also where the front end reports
6056+ problems with its destructor. */
6057+ call_position = &dip->variable->source_corresp.decl_position;
6058+ error_position = *call_position;
6059+ } /* if */
60356060 /* Set the cleanup state to what it should be after the destruction,
60366061 because as soon as we start the destruction it's the destructor's
60376062 job to deal with partial destruction. */
@@ -6074,7 +6099,9 @@ and not for constructor_init entries in destructors.
60746099 &dedp->init_pos_descr,
60756100 /*have_complete_object=*/TRUE,
60766101 (an_expr_node_ptr)NULL,
6077- effective_insert_loc);
6102+ effective_insert_loc,
6103+ call_position);
6104+ error_position = saved_error_position;
60786105} /* gen_one_destruction */
60796106
60806107#if VLA_DEALLOCATION_REQUIRED
@@ -7834,7 +7861,8 @@ is described by ipdp.
78347861 routine = scope->variant.routine.ptr;
78357862 /* Generate the code for the destruction. */
78367863 add_destructor_call(dip->destructor, ipdp, /*have_complete_object=*/TRUE,
7837- (an_expr_node_ptr)NULL, &insert_location);
7864+ (an_expr_node_ptr)NULL, &insert_location,
7865+ (a_source_position *)NULL);
78387866 /* Mark the variable as referenced from another function. */
78397867 ipdp->variable->referenced_non_locally = TRUE;
78407868 pop_generated_routine_context(scope, region_number, &grcontext);
@@ -11333,7 +11361,8 @@ virtual table table pointer that should be passed to the destructor
1133311361 /*unreachable=*/FALSE);
1133411362 } /* if */
1133511363 add_destructor_call(dip->destructor, ipdp, have_complete_object,
11336- vtt_addr_node, insert_location);
11364+ vtt_addr_node, insert_location,
11365+ (a_source_position *)NULL);
1133711366 error_position = saved_error_position;
1133811367} /* lower_destructor_dynamic_init */
1133911368
@@ -13050,7 +13079,8 @@ tricks.
1305013079 call_node = make_call_node_full(dtor_routine, ptr_node,
1305113080 (an_expr_node_ptr)NULL,
1305213081 /*is_virtual_call=*/dtor_routine->is_virtual,
13053- (an_insert_location *)NULL);
13082+ (an_insert_location *)NULL,
13083+ (a_source_position *)NULL);
1305413084 check_assertion(call_node != NULL);
1305513085 if (dtor_routine->is_virtual) {
1305613086 /* The destructor is virtual, so rewrite the virtual call. */
@@ -15945,7 +15975,8 @@ ABI.
1594515975 var_rvalue_expr(vtt_ptr_var), &insert_location);
1594615976 /* Generate the code to call the destructor. */
1594715977 add_destructor_call(dtor_routine, &ipd, /*have_complete_object=*/FALSE,
15948- (an_expr_node_ptr)NULL, &insert_location);
15978+ (an_expr_node_ptr)NULL, &insert_location,
15979+ (a_source_position *)NULL);
1594915980 pop_generated_routine_context(scope, region_number, &grcontext);
1595015981 return routine;
1595115982} /* make_subobject_destruction_routine */
0 commit comments