@@ -5956,14 +5956,15 @@ typedef struct a_builtin_call_adjustment {
59565956 arguments, this field will be NULL. */
59575957 a_symbol_ptr
59585958 overloaded_function_symbol;
5959- /* If non-NULL, the symbol for operator new/delete
5960- to be used in place of __builtin_operator_new/
5961- builtin_operator_delete. */
5959+ /* If non-NULL, the symbol for the function to be
5960+ called in place of the builtin (e.g., operator
5961+ new/delete in place of __builtin_operator_new/
5962+ __builtin_operator_delete). */
59625963 a_name_reference_ptr
59635964 name_reference;
59645965 /* If non-NULL, the special name reference to use
5965- to represent __builtin_operator_new/
5966- __builtin_operator_delete to a back end. */
5966+ to represent the builtin (e.g.,
5967+ __builtin_operator_new) to a back end. */
59675968 int n_args; /* The number of arguments the builtin expects. */
59685969 int dispatch_arg;
59695970 /* The argument number of the "dispatch type", if any.
@@ -6257,6 +6258,38 @@ be called to check and adjust the argument and routine types as needed.
62576258 } /* if */
62586259 }
62596260 break;
6261+ case bufk_current_exception:
6262+ case bufk_uncaught_exceptions:
6263+ { /* The GCC C++ standard library uses __builtin_current_exception in
6264+ constexpr functions, since std::current_exception is not declared
6265+ constexpr there. The builtin is equivalent to
6266+ std::current_exception (which can be evaluated during constant
6267+ evaluation; see check_for_constexpr_intrinsic), and so the call is
6268+ replaced by a call to that function (with a name reference that
6269+ lets a back end recreate the original source). Likewise for
6270+ __builtin_uncaught_exceptions and std::uncaught_exceptions. If the
6271+ std function is not declared, the builtin is kept (and
6272+ __builtin_uncaught_exceptions is then evaluated directly; see
6273+ do_constexpr_builtin_function). */
6274+ a_symbol_ptr sym = look_up_name_string_in_std(
6275+ bfk == bufk_current_exception
6276+ ? "current_exception"
6277+ : "uncaught_exceptions");
6278+ if (sym != NULL) sym = fundamental_symbol_of(sym);
6279+ if (sym != NULL && (symbol_is(sym, sk_routine) ||
6280+ symbol_is(sym, sk_overloaded_function))) {
6281+ bcap->overloaded_function_symbol = sym;
6282+ bcap->name_reference = alloc_name_reference();
6283+ bcap->name_reference->special_kind =
6284+ bfk == bufk_current_exception
6285+ ? sfk_builtin_current_exception
6286+ : sfk_builtin_uncaught_exceptions;
6287+ bcap->callback = nullptr;
6288+ } else {
6289+ requires_processing = FALSE;
6290+ } /* if */
6291+ }
6292+ break;
62606293 case bfk_elementwise_abs:
62616294 case bfk_elementwise_acos:
62626295 case bfk_elementwise_asin:
@@ -8180,6 +8213,7 @@ and bound_function_selector are expected to be NULL in that case.
81808213 an_expr_node_ptr castexp;
81818214#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
81828215 a_boolean call_folded_to_constant = FALSE;
8216+ an_expr_node_ptr function_call_node = NULL;
81838217#if BUILTIN_FUNCTIONS_ENABLED
81848218 a_routine_ptr operand_routine;
81858219 a_builtin_call_adjustment
@@ -8762,8 +8796,9 @@ and bound_function_selector are expected to be NULL in that case.
87628796 routine = NULL;
87638797 unknown_dependent_function = FALSE;
87648798 if (bcap->overloaded_function_symbol != NULL) {
8765- /* The builtin is being replaced by a call to a global overloaded
8766- operator function; use that symbol to do the overload resolution. */
8799+ /* The builtin is being replaced by a call to another function (e.g.,
8800+ a global overloaded operator function); use that symbol to do the
8801+ overload resolution. */
87678802 overloaded_function_symbol = bcap->overloaded_function_symbol;
87688803 overloaded_function_case = TRUE;
87698804 operand->is_qualified_name = TRUE;
@@ -9060,7 +9095,6 @@ and bound_function_selector are expected to be NULL in that case.
90609095#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
90619096 } /* if */
90629097 } /* if */
9063- an_expr_node_ptr function_call_node = NULL;
90649098 assemble_function_call(operand, bound_function_selector, argument_list,
90659099 /*compiler_generated=*/FALSE,
90669100 arg_dep_lookup_suppressed,
@@ -9104,13 +9138,15 @@ and bound_function_selector are expected to be NULL in that case.
91049138#if BUILTIN_FUNCTIONS_ENABLED
91059139 if (bcap != NULL) {
91069140 if (bcap->name_reference != NULL && !is_error_operand(result)) {
9107- /* The builtin call has been replaced by a call to the appropriate
9108- operator new/delete; use a name reference to communicate this to the
9109- back end so the original source can be recreated. */
9141+ /* The builtin call has been replaced by a call to another function
9142+ (e.g., the appropriate operator new/delete); use a name reference to
9143+ communicate this to the back end so the original source can be
9144+ recreated. (The call node can be below the expression in result,
9145+ e.g., when the function returns a class.) */
91109146 an_expr_node_ptr operand_node;
9111- check_assertion(result->kind == ok_expression &&
9112- node_is_operator(result->variant.expression , eok_call));
9113- operand_node = result->variant.expression ->variant.operation.operands;
9147+ check_assertion(function_call_node != NULL &&
9148+ node_is_operator(function_call_node , eok_call));
9149+ operand_node = function_call_node ->variant.operation.operands;
91149150 switch (operand_node->kind) {
91159151 case enk_routine:
91169152 operand_node->variant.routine.name_reference = bcap->name_reference;
0 commit comments