@@ -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,39 @@ 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 a
6265+ constexpr function. The builtin is equivalent to
6266+ std::current_exception, and so the call is replaced by a call to
6267+ that function, with a name reference that lets a back end recreate
6268+ the original source and that lets the call be evaluated during
6269+ constant evaluation (see nonconstexpr_intrinsic_call_allowed in
6270+ interpret.c). Likewise for
6271+ __builtin_uncaught_exceptions and std::uncaught_exceptions. If the
6272+ std function is not declared, the builtin is kept (and
6273+ __builtin_uncaught_exceptions is then evaluated directly; see
6274+ do_constexpr_builtin_function). */
6275+ a_symbol_ptr sym = look_up_name_string_in_std(
6276+ bfk == bufk_current_exception
6277+ ? "current_exception"
6278+ : "uncaught_exceptions");
6279+ if (sym != NULL) sym = fundamental_symbol_of(sym);
6280+ if (sym != NULL && (symbol_is(sym, sk_routine) ||
6281+ symbol_is(sym, sk_overloaded_function))) {
6282+ bcap->overloaded_function_symbol = sym;
6283+ bcap->name_reference = alloc_name_reference();
6284+ bcap->name_reference->special_kind =
6285+ bfk == bufk_current_exception
6286+ ? sfk_builtin_current_exception
6287+ : sfk_builtin_uncaught_exceptions;
6288+ bcap->callback = nullptr;
6289+ } else {
6290+ requires_processing = FALSE;
6291+ } /* if */
6292+ }
6293+ break;
62606294 case bfk_elementwise_abs:
62616295 case bfk_elementwise_acos:
62626296 case bfk_elementwise_asin:
@@ -8180,6 +8214,7 @@ and bound_function_selector are expected to be NULL in that case.
81808214 an_expr_node_ptr castexp;
81818215#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
81828216 a_boolean call_folded_to_constant = FALSE;
8217+ an_expr_node_ptr function_call_node = NULL;
81838218#if BUILTIN_FUNCTIONS_ENABLED
81848219 a_routine_ptr operand_routine;
81858220 a_builtin_call_adjustment
@@ -8762,8 +8797,9 @@ and bound_function_selector are expected to be NULL in that case.
87628797 routine = NULL;
87638798 unknown_dependent_function = FALSE;
87648799 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. */
8800+ /* The builtin is being replaced by a call to another function (e.g.,
8801+ a global overloaded operator function); use that symbol to do the
8802+ overload resolution. */
87678803 overloaded_function_symbol = bcap->overloaded_function_symbol;
87688804 overloaded_function_case = TRUE;
87698805 operand->is_qualified_name = TRUE;
@@ -9060,7 +9096,6 @@ and bound_function_selector are expected to be NULL in that case.
90609096#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
90619097 } /* if */
90629098 } /* if */
9063- an_expr_node_ptr function_call_node = NULL;
90649099 assemble_function_call(operand, bound_function_selector, argument_list,
90659100 /*compiler_generated=*/FALSE,
90669101 arg_dep_lookup_suppressed,
@@ -9104,13 +9139,15 @@ and bound_function_selector are expected to be NULL in that case.
91049139#if BUILTIN_FUNCTIONS_ENABLED
91059140 if (bcap != NULL) {
91069141 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. */
9142+ /* The builtin call has been replaced by a call to another function
9143+ (e.g., the appropriate operator new/delete); use a name reference to
9144+ communicate this to the back end so the original source can be
9145+ recreated. (The call node can be below the expression in result,
9146+ e.g., when the function returns a class.) */
91109147 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;
9148+ check_assertion(function_call_node != NULL &&
9149+ node_is_operator(function_call_node , eok_call));
9150+ operand_node = function_call_node ->variant.operation.operands;
91149151 switch (operand_node->kind) {
91159152 case enk_routine:
91169153 operand_node->variant.routine.name_reference = bcap->name_reference;
0 commit comments