Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/cp_gen_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -7260,14 +7260,12 @@ successfully emitted.
#endif /* TEMPLATE_INSTANTIATIONS_IN_SOURCE_SEQUENCE_LISTS */
#if BUILTIN_FUNCTIONS_ENABLED
if (use_name_reference &&
(nrp->special_kind ==
(a_special_function_kind)sfk_builtin_operator_new ||
nrp->special_kind ==
(a_special_function_kind)sfk_builtin_operator_delete ||
nrp->special_kind ==
(a_special_function_kind)sfk_gnu_atomic_nongeneric_function ||
nrp->special_kind ==
(a_special_function_kind)sfk_gnu_sync_concrete_function)) {
(special_kind_is(nrp, sfk_builtin_operator_new) ||
special_kind_is(nrp, sfk_builtin_operator_delete) ||
special_kind_is(nrp, sfk_builtin_current_exception) ||
special_kind_is(nrp, sfk_builtin_uncaught_exceptions) ||
special_kind_is(nrp, sfk_gnu_atomic_nongeneric_function) ||
special_kind_is(nrp, sfk_gnu_sync_concrete_function))) {
/* These are special cases handled by gen_name_from_routine_node. */
use_name_reference = FALSE;
} /* if */
Expand Down Expand Up @@ -7438,7 +7436,9 @@ qualified is TRUE, force the generation of a qualified name.
(special_kind_is(nrp, sfk_gnu_sync_concrete_function) ||
special_kind_is(nrp, sfk_gnu_atomic_nongeneric_function) ||
special_kind_is(nrp, sfk_builtin_operator_new) ||
special_kind_is(nrp, sfk_builtin_operator_delete))) {
special_kind_is(nrp, sfk_builtin_operator_delete) ||
special_kind_is(nrp, sfk_builtin_current_exception) ||
special_kind_is(nrp, sfk_builtin_uncaught_exceptions))) {
switch (nrp->special_kind) {
case sfk_gnu_sync_concrete_function:
case sfk_gnu_atomic_nongeneric_function:
Expand Down Expand Up @@ -7484,6 +7484,12 @@ qualified is TRUE, force the generation of a qualified name.
case sfk_builtin_operator_delete:
write_tok_str("__builtin_operator_delete");
break;
case sfk_builtin_current_exception:
write_tok_str("__builtin_current_exception");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
break;
case sfk_builtin_uncaught_exceptions:
write_tok_str("__builtin_uncaught_exceptions");
break;
default:
unexpected_condition();
} /* switch */
Expand Down
9 changes: 9 additions & 0 deletions src/decls.c
Original file line number Diff line number Diff line change
Expand Up @@ -10585,6 +10585,15 @@ skip_overloading:;
locator->symbol_header->has_intrinsic_name) {
check_for_constexpr_intrinsic(routine_ptr, locator->symbol_header);
} /* if */
} else if (!redeclaration && innermost_function_scope == NULL &&
constexpr_exceptions_enabled &&
locator->symbol_header != NULL &&
locator->symbol_header->has_intrinsic_name) {
/* Some library functions that can be evaluated during constant evaluation
are not necessarily declared constexpr (e.g., the GCC C++ standard
library, as of GCC 16, does not declare std::current_exception
constexpr). See check_for_constexpr_intrinsic. */
check_for_constexpr_intrinsic(routine_ptr, locator->symbol_header);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} /* if */
#if GNU_EXTENSIONS_ALLOWED
if (gcc_pragma_options_stack != NULL && !func_info->is_main_function) {
Expand Down
3 changes: 3 additions & 0 deletions src/error_msg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3689,5 +3689,8 @@ ec_constexpr_exception_escapes_nonthrowing;;"std::terminate is called because an
ec_constexpr_exception_during_unwinding;;"std::terminate is called because an exception escapes from a destructor during stack unwinding"
ec_constexpr_exception_in_handler_init;;"std::terminate is called because an exception escapes from the initialization of a handler parameter"
ec_constexpr_exception_from_exception_dtor;;"std::terminate is called because the destructor of an exception object exits by throwing an exception"
ec_constexpr_exception_thrown_here;;"the exception was thrown here"
ec_constexpr_exception_object_not_destroyed;;"an exception object of type %t is not destroyed at the end of constant evaluation"
ec_constexpr_rethrow_null_exception_ptr;;"std::rethrow_exception is called with a null std::exception_ptr"
###############################################################################

64 changes: 50 additions & 14 deletions src/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5956,14 +5956,15 @@ typedef struct a_builtin_call_adjustment {
arguments, this field will be NULL. */
a_symbol_ptr
overloaded_function_symbol;
/* If non-NULL, the symbol for operator new/delete
to be used in place of __builtin_operator_new/
builtin_operator_delete. */
/* If non-NULL, the symbol for the function to be
called in place of the builtin (e.g., operator
new/delete in place of __builtin_operator_new/
__builtin_operator_delete). */
a_name_reference_ptr
name_reference;
/* If non-NULL, the special name reference to use
to represent __builtin_operator_new/
__builtin_operator_delete to a back end. */
to represent the builtin (e.g.,
__builtin_operator_new) to a back end. */
int n_args; /* The number of arguments the builtin expects. */
int dispatch_arg;
/* The argument number of the "dispatch type", if any.
Expand Down Expand Up @@ -6257,6 +6258,38 @@ be called to check and adjust the argument and routine types as needed.
} /* if */
}
break;
case bufk_current_exception:
case bufk_uncaught_exceptions:
{ /* The GCC C++ standard library uses __builtin_current_exception in
constexpr functions, since std::current_exception is not declared
constexpr there. The builtin is equivalent to
std::current_exception (which can be evaluated during constant
evaluation; see check_for_constexpr_intrinsic), and so the call is
replaced by a call to that function (with a name reference that
lets a back end recreate the original source). Likewise for
__builtin_uncaught_exceptions and std::uncaught_exceptions. If the
std function is not declared, the builtin is kept (and
__builtin_uncaught_exceptions is then evaluated directly; see
do_constexpr_builtin_function). */
a_symbol_ptr sym = look_up_name_string_in_std(
bfk == bufk_current_exception
? "current_exception"
: "uncaught_exceptions");
if (sym != NULL) sym = fundamental_symbol_of(sym);
if (sym != NULL && (symbol_is(sym, sk_routine) ||
symbol_is(sym, sk_overloaded_function))) {
bcap->overloaded_function_symbol = sym;
bcap->name_reference = alloc_name_reference();
bcap->name_reference->special_kind =
bfk == bufk_current_exception
? sfk_builtin_current_exception
: sfk_builtin_uncaught_exceptions;
bcap->callback = nullptr;
} else {
requires_processing = FALSE;
} /* if */
}
break;
case bfk_elementwise_abs:
case bfk_elementwise_acos:
case bfk_elementwise_asin:
Expand Down Expand Up @@ -8180,6 +8213,7 @@ and bound_function_selector are expected to be NULL in that case.
an_expr_node_ptr castexp;
#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
a_boolean call_folded_to_constant = FALSE;
an_expr_node_ptr function_call_node = NULL;
#if BUILTIN_FUNCTIONS_ENABLED
a_routine_ptr operand_routine;
a_builtin_call_adjustment
Expand Down Expand Up @@ -8762,8 +8796,9 @@ and bound_function_selector are expected to be NULL in that case.
routine = NULL;
unknown_dependent_function = FALSE;
if (bcap->overloaded_function_symbol != NULL) {
/* The builtin is being replaced by a call to a global overloaded
operator function; use that symbol to do the overload resolution. */
/* The builtin is being replaced by a call to another function (e.g.,
a global overloaded operator function); use that symbol to do the
overload resolution. */
overloaded_function_symbol = bcap->overloaded_function_symbol;
overloaded_function_case = TRUE;
operand->is_qualified_name = TRUE;
Expand Down Expand Up @@ -9060,7 +9095,6 @@ and bound_function_selector are expected to be NULL in that case.
#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
} /* if */
} /* if */
an_expr_node_ptr function_call_node = NULL;
assemble_function_call(operand, bound_function_selector, argument_list,
/*compiler_generated=*/FALSE,
arg_dep_lookup_suppressed,
Expand Down Expand Up @@ -9104,13 +9138,15 @@ and bound_function_selector are expected to be NULL in that case.
#if BUILTIN_FUNCTIONS_ENABLED
if (bcap != NULL) {
if (bcap->name_reference != NULL && !is_error_operand(result)) {
/* The builtin call has been replaced by a call to the appropriate
operator new/delete; use a name reference to communicate this to the
back end so the original source can be recreated. */
/* The builtin call has been replaced by a call to another function
(e.g., the appropriate operator new/delete); use a name reference to
communicate this to the back end so the original source can be
recreated. (The call node can be below the expression in result,
e.g., when the function returns a class.) */
an_expr_node_ptr operand_node;
check_assertion(result->kind == ok_expression &&
node_is_operator(result->variant.expression, eok_call));
operand_node = result->variant.expression->variant.operation.operands;
check_assertion(function_call_node != NULL &&
node_is_operator(function_call_node, eok_call));
operand_node = function_call_node->variant.operation.operands;
switch (operand_node->kind) {
case enk_routine:
operand_node->variant.routine.name_reference = bcap->name_reference;
Expand Down
1 change: 1 addition & 0 deletions src/folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -11043,6 +11043,7 @@ pseudo_call can be NULL if that information is not needed.
case bufk_FILE_NAME:
case bfk_FUNCTION:
case bufk_FUNCSIG:
case bufk_eh_ptr_adjust_ref:
case bfk_add_overflow_p:
case bfk_add_overflow:
case bfk_uadd_overflow:
Expand Down
4 changes: 4 additions & 0 deletions src/ifc_modules_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2137,8 +2137,10 @@ Return the declaration index for the routine.
/* FIXME: Implement these. */
break;
#if BUILTIN_FUNCTIONS_ENABLED
case sfk_builtin_current_exception:
case sfk_builtin_operator_delete:
case sfk_builtin_operator_new:
case sfk_builtin_uncaught_exceptions:
#endif /* BUILTIN_FUNCTIONS_ENABLED */
case sfk_deduction_guide:
#if MICROSOFT_EXTENSIONS_ALLOWED
Expand Down Expand Up @@ -3122,8 +3124,10 @@ for the function type.
/* FIXME: Implement these. */
break;
#if BUILTIN_FUNCTIONS_ENABLED
case sfk_builtin_current_exception:
case sfk_builtin_operator_delete:
case sfk_builtin_operator_new:
case sfk_builtin_uncaught_exceptions:
#endif /* BUILTIN_FUNCTIONS_ENABLED */
case sfk_deduction_guide:
#if MICROSOFT_EXTENSIONS_ALLOWED
Expand Down
8 changes: 8 additions & 0 deletions src/il_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,12 @@ enum a_special_function_kind : a_byte {
sfk_builtin_operator_delete,
/* Represents __builtin_operator_delete (which has been
replaced by operator delete). */
sfk_builtin_current_exception,
/* Represents __builtin_current_exception (which has
been replaced by std::current_exception). */
sfk_builtin_uncaught_exceptions,
/* Represents __builtin_uncaught_exceptions (which has
been replaced by std::uncaught_exceptions). */
#endif /* BUILTIN_FUNCTIONS_ENABLED */
sfk_last /* Must be last. */
};
Expand Down Expand Up @@ -4594,6 +4600,8 @@ EXTERN_CONSTINIT_ARRAY(a_const_char*, db_special_function_kinds, sfk_last + 1)
"gnu atomic generic function",
"__builtin_operator_new",
"__builtin_operator_delete",
"__builtin_current_exception",
"__builtin_uncaught_exceptions",
#endif /* BUILTIN_FUNCTIONS_ENABLED */
"last" /* used to check that initialization is right. */
}
Expand Down
6 changes: 6 additions & 0 deletions src/il_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,12 @@ Print the name of a special function kind.
case sfk_builtin_operator_delete:
s = "sfk_builtin_operator_delete";
break;
case sfk_builtin_current_exception:
s = "sfk_builtin_current_exception";
break;
case sfk_builtin_uncaught_exceptions:
s = "sfk_builtin_uncaught_exceptions";
break;
#endif /* BUILTIN_FUNCTIONS_ENABLED */
default: s = "**BAD SPECIAL FUNCTION KIND**";
} /* switch */
Expand Down
Loading
Loading