static int can_convert_eh (tree to, tree from) { to = non_reference (to); from = non_reference (from); if (TYPE_PTR_P (to) && TYPE_PTR_P (from)) { to = TREE_TYPE (to); from = TREE_TYPE (from); if (! at_least_as_qualified_p (to, from)) return 0; if (VOID_TYPE_P (to)) return 1; /* Else fall through. */ } if (CLASS_TYPE_P (to) && CLASS_TYPE_P (from) && publicly_uniquely_derived_p (to, from)) return 1; return 0; }
static void initialize_handler_parm (tree decl, tree exp) { tree init; tree init_type; /* Make sure we mark the catch param as used, otherwise we'll get a warning about an unused ((anonymous)). */ TREE_USED (decl) = 1; /* Figure out the type that the initializer is. Pointers are returned adjusted by value from __cxa_begin_catch. Others are returned by reference. */ init_type = TREE_TYPE (decl); if (! TYPE_PTR_P (init_type) && TREE_CODE (init_type) != REFERENCE_TYPE) init_type = build_reference_type (init_type); choose_personality_routine (decl_is_java_type (init_type, 0) ? lang_java : lang_cplusplus); /* Since pointers are passed by value, initialize a reference to pointer catch parm with the address of the temporary. */ if (TREE_CODE (init_type) == REFERENCE_TYPE && TYPE_PTR_P (TREE_TYPE (init_type))) exp = build_unary_op (ADDR_EXPR, exp, 1); exp = ocp_convert (init_type, exp, CONV_IMPLICIT|CONV_FORCE_TEMP, 0); init = convert_from_reference (exp); /* If the constructor for the catch parm exits via an exception, we must call terminate. See eh23.C. */ if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) { /* Generate the copy constructor call directly so we can wrap it. See also expand_default_init. */ init = ocp_convert (TREE_TYPE (decl), init, CONV_IMPLICIT|CONV_FORCE_TEMP, 0); init = build1 (MUST_NOT_THROW_EXPR, TREE_TYPE (init), init); } /* Let `cp_finish_decl' know that this initializer is ok. */ DECL_INITIAL (decl) = error_mark_node; decl = pushdecl (decl); start_decl_1 (decl); cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING|DIRECT_BIND); }
tree maybe_resolve_dummy (tree object, bool add_capture_p) { if (!is_dummy_object (object)) return object; tree type = TYPE_MAIN_VARIANT (TREE_TYPE (object)); gcc_assert (!TYPE_PTR_P (type)); if (type != current_class_type && current_class_type && LAMBDA_TYPE_P (current_class_type) && lambda_function (current_class_type) && DERIVED_FROM_P (type, current_nonlambda_class_type ())) { /* In a lambda, need to go through 'this' capture. */ tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type); tree cap = lambda_expr_this_capture (lam, add_capture_p); if (cap && cap != error_mark_node) object = build_x_indirect_ref (EXPR_LOCATION (object), cap, RO_NULL, tf_warning_or_error); } return object; }
tree perform_qualification_conversions (tree type, tree expr) { tree expr_type; expr_type = TREE_TYPE (expr); if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type) && comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type))) return build_nop (type, expr); else if (TYPE_PTR_TO_MEMBER_P (type) && TYPE_PTR_TO_MEMBER_P (expr_type) && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type), TYPE_PTRMEM_CLASS_TYPE (expr_type)) && comp_ptr_ttypes (TYPE_PTRMEM_POINTED_TO_TYPE (type), TYPE_PTRMEM_POINTED_TO_TYPE (expr_type))) return build_nop (type, expr); else return error_mark_node; }
static void initialize_handler_parm (tree decl, tree exp) { tree init; tree init_type; /* Make sure we mark the catch param as used, otherwise we'll get a warning about an unused ((anonymous)). */ TREE_USED (decl) = 1; DECL_READ_P (decl) = 1; /* Figure out the type that the initializer is. Pointers are returned adjusted by value from __cxa_begin_catch. Others are returned by reference. */ init_type = TREE_TYPE (decl); if (!POINTER_TYPE_P (init_type)) init_type = build_reference_type (init_type); choose_personality_routine (decl_is_java_type (init_type, 0) ? lang_java : lang_cplusplus); /* Since pointers are passed by value, initialize a reference to pointer catch parm with the address of the temporary. */ if (TREE_CODE (init_type) == REFERENCE_TYPE && TYPE_PTR_P (TREE_TYPE (init_type))) exp = cp_build_addr_expr (exp, tf_warning_or_error); exp = ocp_convert (init_type, exp, CONV_IMPLICIT|CONV_FORCE_TEMP, 0, tf_warning_or_error); init = convert_from_reference (exp); /* If the constructor for the catch parm exits via an exception, we must call terminate. See eh23.C. */ if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) { /* Generate the copy constructor call directly so we can wrap it. See also expand_default_init. */ init = ocp_convert (TREE_TYPE (decl), init, CONV_IMPLICIT|CONV_FORCE_TEMP, 0, tf_warning_or_error); /* Force cleanups now to avoid nesting problems with the MUST_NOT_THROW_EXPR. */ init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); init = build_must_not_throw_expr (init, NULL_TREE); } decl = pushdecl (decl); start_decl_1 (decl, true); cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING|DIRECT_BIND); }
tree cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, tree intype, tree op) { if (!INDIRECT_TYPE_P (type) || !INDIRECT_TYPE_P (intype) || !INDIRECT_TYPE_P (TREE_TYPE (op)) || !CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (op))) || !is_properly_derived_from (TREE_TYPE (type), TREE_TYPE (intype))) return NULL_TREE; return cp_ubsan_maybe_instrument_vptr (loc, op, TREE_TYPE (type), true, TYPE_PTR_P (type) ? UBSAN_DOWNCAST_POINTER : UBSAN_DOWNCAST_REFERENCE); }
static bool decl_is_java_type (tree decl, int err) { bool r = (TYPE_PTR_P (decl) && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE && TYPE_FOR_JAVA (TREE_TYPE (decl))); if (err) { if (TREE_CODE (decl) == REFERENCE_TYPE && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE && TYPE_FOR_JAVA (TREE_TYPE (decl))) { /* Can't throw a reference. */ error ("type %qT is disallowed in Java %<throw%> or %<catch%>", decl); } if (r) { tree jthrow_node = IDENTIFIER_GLOBAL_VALUE (get_identifier ("jthrowable")); if (jthrow_node == NULL_TREE) fatal_error (input_location, "call to Java %<catch%> or %<throw%> with %<jthrowable%> undefined"); jthrow_node = TREE_TYPE (TREE_TYPE (jthrow_node)); if (! DERIVED_FROM_P (jthrow_node, TREE_TYPE (decl))) { /* Thrown object must be a Throwable. */ error ("type %qT is not derived from %<java::lang::Throwable%>", TREE_TYPE (decl)); } } } return r; }
static int complete_ptr_ref_or_void_ptr_p (tree type, tree from) { int is_ptr; /* Check complete. */ type = complete_type_or_else (type, from); if (!type) return 0; /* Or a pointer or ref to one, or cv void *. */ is_ptr = TYPE_PTR_P (type); if (is_ptr || TREE_CODE (type) == REFERENCE_TYPE) { tree core = TREE_TYPE (type); if (is_ptr && VOID_TYPE_P (core)) /* OK */; else if (!complete_type_or_else (core, from)) return 0; } return 1; }
tree expand_start_catch_block (tree decl) { tree exp; tree type, init; if (! doing_eh ()) return NULL_TREE; if (decl) { if (!is_admissible_throw_operand_or_catch_parameter (decl, false)) decl = error_mark_node; type = prepare_eh_type (TREE_TYPE (decl)); mark_used (eh_type_info (type)); } else type = NULL_TREE; /* Call __cxa_end_catch at the end of processing the exception. */ push_eh_cleanup (type); init = do_begin_catch (); /* If there's no decl at all, then all we need to do is make sure to tell the runtime that we've begun handling the exception. */ if (decl == NULL || decl == error_mark_node || init == error_mark_node) finish_expr_stmt (init); /* If the C++ object needs constructing, we need to do that before calling __cxa_begin_catch, so that std::uncaught_exception gets the right value during the copy constructor. */ else if (flag_use_cxa_get_exception_ptr && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) { exp = do_get_exception_ptr (); initialize_handler_parm (decl, exp); finish_expr_stmt (init); } /* Otherwise the type uses a bitwise copy, and we don't have to worry about the value of std::uncaught_exception and therefore can do the copy with the return value of __cxa_end_catch instead. */ else { tree init_type = type; /* Pointers are passed by values, everything else by reference. */ if (!TYPE_PTR_P (type)) init_type = build_pointer_type (type); if (init_type != TREE_TYPE (init)) init = build1 (NOP_EXPR, init_type, init); exp = create_temporary_var (init_type); cp_finish_decl (exp, init, /*init_const_expr=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING); DECL_REGISTER (exp) = 1; initialize_handler_parm (decl, exp); } return type; }
tree expand_start_catch_block (tree decl) { tree exp; tree type, init; if (! doing_eh ()) return NULL_TREE; /* Make sure this declaration is reasonable. */ if (decl && !complete_ptr_ref_or_void_ptr_p (TREE_TYPE (decl), NULL_TREE)) decl = error_mark_node; if (decl) type = prepare_eh_type (TREE_TYPE (decl)); else type = NULL_TREE; if (decl && decl_is_java_type (type, 1)) { /* Java only passes object via pointer and doesn't require adjusting. The java object is immediately before the generic exception header. */ exp = build_exc_ptr (); exp = build1 (NOP_EXPR, build_pointer_type (type), exp); exp = fold_build_pointer_plus (exp, fold_build1_loc (input_location, NEGATE_EXPR, sizetype, TYPE_SIZE_UNIT (TREE_TYPE (exp)))); exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error); initialize_handler_parm (decl, exp); return type; } /* Call __cxa_end_catch at the end of processing the exception. */ push_eh_cleanup (type); init = do_begin_catch (); /* If there's no decl at all, then all we need to do is make sure to tell the runtime that we've begun handling the exception. */ if (decl == NULL || decl == error_mark_node || init == error_mark_node) finish_expr_stmt (init); /* If the C++ object needs constructing, we need to do that before calling __cxa_begin_catch, so that std::uncaught_exception gets the right value during the copy constructor. */ else if (flag_use_cxa_get_exception_ptr && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) { exp = do_get_exception_ptr (); initialize_handler_parm (decl, exp); finish_expr_stmt (init); } /* Otherwise the type uses a bitwise copy, and we don't have to worry about the value of std::uncaught_exception and therefore can do the copy with the return value of __cxa_end_catch instead. */ else { tree init_type = type; /* Pointers are passed by values, everything else by reference. */ if (!TYPE_PTR_P (type)) init_type = build_pointer_type (type); if (init_type != TREE_TYPE (init)) init = build1 (NOP_EXPR, init_type, init); exp = create_temporary_var (init_type); DECL_REGISTER (exp) = 1; cp_finish_decl (exp, init, /*init_const_expr=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING); initialize_handler_parm (decl, exp); } return type; }