1 /* Handle exceptional things in C++.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann <tiemann@cygnus.com>
5 Rewritten by Mike Stump <mrs@cygnus.com>, based upon an
6 initial re-implementation courtesy Tad Hunt.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include "coretypes.h"
39 #include "tree-inline.h"
40 #include "tree-iterator.h"
42 static void push_eh_cleanup (tree
);
43 static tree
prepare_eh_type (tree
);
44 static tree
build_eh_type_type (tree
);
45 static tree
do_begin_catch (void);
46 static int dtor_nothrow (tree
);
47 static tree
do_end_catch (tree
);
48 static bool decl_is_java_type (tree decl
, int err
);
49 static void initialize_handler_parm (tree
, tree
);
50 static tree
do_allocate_exception (tree
);
51 static tree
wrap_cleanups_r (tree
*, int *, void *);
52 static int complete_ptr_ref_or_void_ptr_p (tree
, tree
);
53 static bool is_admissible_throw_operand (tree
);
54 static int can_convert_eh (tree
, tree
);
55 static tree
cp_protect_cleanup_actions (void);
57 /* Sets up all the global eh stuff that needs to be initialized at the
58 start of compilation. */
61 init_exception_processing (void)
65 /* void std::terminate (); */
66 push_namespace (std_identifier
);
67 tmp
= build_function_type (void_type_node
, void_list_node
);
68 terminate_node
= build_cp_library_fn_ptr ("terminate", tmp
);
69 TREE_THIS_VOLATILE (terminate_node
) = 1;
70 TREE_NOTHROW (terminate_node
) = 1;
73 /* void __cxa_call_unexpected(void *); */
74 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
75 tmp
= build_function_type (void_type_node
, tmp
);
77 = push_throw_library_fn (get_identifier ("__cxa_call_unexpected"), tmp
);
79 eh_personality_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
80 ? "__gxx_personality_sj0"
81 : "__gxx_personality_v0");
83 lang_eh_runtime_type
= build_eh_type_type
;
84 lang_protect_cleanup_actions
= &cp_protect_cleanup_actions
;
87 /* Returns an expression to be executed if an unhandled exception is
88 propagated out of a cleanup region. */
91 cp_protect_cleanup_actions (void)
95 When the destruction of an object during stack unwinding exits
96 using an exception ... void terminate(); is called. */
97 return build_call (terminate_node
, NULL_TREE
);
101 prepare_eh_type (tree type
)
103 if (type
== NULL_TREE
)
105 if (type
== error_mark_node
)
106 return error_mark_node
;
108 /* peel back references, so they match. */
109 type
= non_reference (type
);
111 /* Peel off cv qualifiers. */
112 type
= TYPE_MAIN_VARIANT (type
);
117 /* Return the type info for TYPE as used by EH machinery. */
119 eh_type_info (tree type
)
123 if (type
== NULL_TREE
|| type
== error_mark_node
)
126 if (decl_is_java_type (type
, 0))
127 exp
= build_java_class_ref (TREE_TYPE (type
));
129 exp
= get_tinfo_decl (type
);
134 /* Build the address of a typeinfo decl for use in the runtime
135 matching field of the exception model. */
138 build_eh_type_type (tree type
)
140 tree exp
= eh_type_info (type
);
147 return convert (ptr_type_node
, build_address (exp
));
153 return build0 (EXC_PTR_EXPR
, ptr_type_node
);
156 /* Build up a call to __cxa_begin_catch, to tell the runtime that the
157 exception has been handled. */
160 do_begin_catch (void)
164 fn
= get_identifier ("__cxa_begin_catch");
165 if (!get_global_value_if_present (fn
, &fn
))
167 /* Declare void* __cxa_begin_catch (void *). */
168 tree tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
169 fn
= push_library_fn (fn
, build_function_type (ptr_type_node
, tmp
));
172 return build_function_call (fn
, tree_cons (NULL_TREE
, build_exc_ptr (),
176 /* Returns nonzero if cleaning up an exception of type TYPE (which can be
177 NULL_TREE for a ... handler) will not throw an exception. */
180 dtor_nothrow (tree type
)
182 if (type
== NULL_TREE
)
185 if (! TYPE_HAS_DESTRUCTOR (type
))
188 return TREE_NOTHROW (CLASSTYPE_DESTRUCTORS (type
));
191 /* Build up a call to __cxa_end_catch, to destroy the exception object
192 for the current catch block if no others are currently using it. */
195 do_end_catch (tree type
)
199 fn
= get_identifier ("__cxa_end_catch");
200 if (!get_global_value_if_present (fn
, &fn
))
202 /* Declare void __cxa_end_catch (). */
203 fn
= push_void_library_fn (fn
, void_list_node
);
204 /* This can throw if the destructor for the exception throws. */
205 TREE_NOTHROW (fn
) = 0;
208 cleanup
= build_function_call (fn
, NULL_TREE
);
209 TREE_NOTHROW (cleanup
) = dtor_nothrow (type
);
214 /* This routine creates the cleanup for the current exception. */
217 push_eh_cleanup (tree type
)
219 finish_decl_cleanup (NULL_TREE
, do_end_catch (type
));
222 /* Return nonzero value if DECL is a Java type suitable for catch or
226 decl_is_java_type (tree decl
, int err
)
228 bool r
= (TREE_CODE (decl
) == POINTER_TYPE
229 && TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
230 && TYPE_FOR_JAVA (TREE_TYPE (decl
)));
234 if (TREE_CODE (decl
) == REFERENCE_TYPE
235 && TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
236 && TYPE_FOR_JAVA (TREE_TYPE (decl
)))
238 /* Can't throw a reference. */
239 error ("type `%T' is disallowed in Java `throw' or `catch'",
246 = IDENTIFIER_GLOBAL_VALUE (get_identifier ("jthrowable"));
248 if (jthrow_node
== NULL_TREE
)
250 ("call to Java `catch' or `throw' with `jthrowable' undefined");
252 jthrow_node
= TREE_TYPE (TREE_TYPE (jthrow_node
));
254 if (! DERIVED_FROM_P (jthrow_node
, TREE_TYPE (decl
)))
256 /* Thrown object must be a Throwable. */
257 error ("type `%T' is not derived from `java::lang::Throwable'",
266 /* Select the personality routine to be used for exception handling,
267 or issue an error if we need two different ones in the same
269 ??? At present eh_personality_libfunc is set to
270 __gxx_personality_(sj|v)0 in init_exception_processing - should it
271 be done here instead? */
273 choose_personality_routine (enum languages lang
)
288 if (lang
!= lang_cplusplus
)
293 if (lang
!= lang_java
)
298 ; /* Proceed to language selection. */
309 eh_personality_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
310 ? "__gcj_personality_sj0"
311 : "__gcj_personality_v0");
320 error ("mixing C++ and Java catches in a single translation unit");
324 /* Initialize the catch parameter DECL. */
327 initialize_handler_parm (tree decl
, tree exp
)
332 /* Make sure we mark the catch param as used, otherwise we'll get a
333 warning about an unused ((anonymous)). */
334 TREE_USED (decl
) = 1;
336 /* Figure out the type that the initializer is. Pointers are returned
337 adjusted by value from __cxa_begin_catch. Others are returned by
339 init_type
= TREE_TYPE (decl
);
340 if (! TYPE_PTR_P (init_type
)
341 && TREE_CODE (init_type
) != REFERENCE_TYPE
)
342 init_type
= build_reference_type (init_type
);
344 choose_personality_routine (decl_is_java_type (init_type
, 0)
345 ? lang_java
: lang_cplusplus
);
347 /* Since pointers are passed by value, initialize a reference to
348 pointer catch parm with the address of the temporary. */
349 if (TREE_CODE (init_type
) == REFERENCE_TYPE
350 && TYPE_PTR_P (TREE_TYPE (init_type
)))
351 exp
= build_unary_op (ADDR_EXPR
, exp
, 1);
353 exp
= ocp_convert (init_type
, exp
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, 0);
355 init
= convert_from_reference (exp
);
357 /* If the constructor for the catch parm exits via an exception, we
358 must call terminate. See eh23.C. */
359 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
361 /* Generate the copy constructor call directly so we can wrap it.
362 See also expand_default_init. */
363 init
= ocp_convert (TREE_TYPE (decl
), init
,
364 CONV_IMPLICIT
|CONV_FORCE_TEMP
, 0);
365 init
= build1 (MUST_NOT_THROW_EXPR
, TREE_TYPE (init
), init
);
368 /* Let `cp_finish_decl' know that this initializer is ok. */
369 DECL_INITIAL (decl
) = error_mark_node
;
370 decl
= pushdecl (decl
);
373 cp_finish_decl (decl
, init
, NULL_TREE
,
374 LOOKUP_ONLYCONVERTING
|DIRECT_BIND
);
377 /* Call this to start a catch block. DECL is the catch parameter. */
380 expand_start_catch_block (tree decl
)
382 tree exp
= NULL_TREE
;
389 /* Make sure this declaration is reasonable. */
390 if (decl
&& !complete_ptr_ref_or_void_ptr_p (TREE_TYPE (decl
), NULL_TREE
))
394 type
= prepare_eh_type (TREE_TYPE (decl
));
403 if (decl_is_java_type (type
, 1))
405 /* Java only passes object via pointer and doesn't require
406 adjusting. The java object is immediately before the
407 generic exception header. */
408 init
= build_exc_ptr ();
409 init
= build1 (NOP_EXPR
, build_pointer_type (type
), init
);
410 init
= build2 (MINUS_EXPR
, TREE_TYPE (init
), init
,
411 TYPE_SIZE_UNIT (TREE_TYPE (init
)));
412 init
= build_indirect_ref (init
, NULL
);
417 /* C++ requires that we call __cxa_begin_catch to get the
418 pointer to the actual object. */
419 init
= do_begin_catch ();
422 exp
= create_temporary_var (ptr_type_node
);
423 DECL_REGISTER (exp
) = 1;
424 cp_finish_decl (exp
, init
, NULL_TREE
, LOOKUP_ONLYCONVERTING
);
425 finish_expr_stmt (build_modify_expr (exp
, INIT_EXPR
, init
));
428 finish_expr_stmt (do_begin_catch ());
430 /* C++ requires that we call __cxa_end_catch at the end of
431 processing the exception. */
433 push_eh_cleanup (type
);
436 initialize_handler_parm (decl
, exp
);
442 /* Call this to end a catch block. Its responsible for emitting the
443 code to handle jumping back to the correct place, and for emitting
444 the label to jump to if this catch block didn't match. */
447 expand_end_catch_block (void)
452 /* The exception being handled is rethrown if control reaches the end of
453 a handler of the function-try-block of a constructor or destructor. */
454 if (in_function_try_handler
455 && (DECL_CONSTRUCTOR_P (current_function_decl
)
456 || DECL_DESTRUCTOR_P (current_function_decl
)))
457 finish_expr_stmt (build_throw (NULL_TREE
));
461 begin_eh_spec_block (void)
463 tree r
= build_stmt (EH_SPEC_BLOCK
, NULL_TREE
, NULL_TREE
);
465 EH_SPEC_STMTS (r
) = push_stmt_list ();
470 finish_eh_spec_block (tree raw_raises
, tree eh_spec_block
)
474 EH_SPEC_STMTS (eh_spec_block
) = pop_stmt_list (EH_SPEC_STMTS (eh_spec_block
));
476 /* Strip cv quals, etc, from the specification types. */
477 for (raises
= NULL_TREE
;
478 raw_raises
&& TREE_VALUE (raw_raises
);
479 raw_raises
= TREE_CHAIN (raw_raises
))
481 tree type
= prepare_eh_type (TREE_VALUE (raw_raises
));
482 tree tinfo
= eh_type_info (type
);
485 raises
= tree_cons (NULL_TREE
, type
, raises
);
488 EH_SPEC_RAISES (eh_spec_block
) = raises
;
491 /* Return a pointer to a buffer for an exception object of type TYPE. */
494 do_allocate_exception (tree type
)
498 fn
= get_identifier ("__cxa_allocate_exception");
499 if (!get_global_value_if_present (fn
, &fn
))
501 /* Declare void *__cxa_allocate_exception(size_t). */
502 tree tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
503 fn
= push_library_fn (fn
, build_function_type (ptr_type_node
, tmp
));
506 return build_function_call (fn
, tree_cons (NULL_TREE
, size_in_bytes (type
),
510 /* Call __cxa_free_exception from a cleanup. This is never invoked
511 directly, but see the comment for stabilize_throw_expr. */
514 do_free_exception (tree ptr
)
518 fn
= get_identifier ("__cxa_free_exception");
519 if (!get_global_value_if_present (fn
, &fn
))
521 /* Declare void __cxa_free_exception (void *). */
522 fn
= push_void_library_fn (fn
, tree_cons (NULL_TREE
, ptr_type_node
,
526 return build_function_call (fn
, tree_cons (NULL_TREE
, ptr
, NULL_TREE
));
529 /* Wrap all cleanups for TARGET_EXPRs in MUST_NOT_THROW_EXPR.
530 Called from build_throw via walk_tree_without_duplicates. */
533 wrap_cleanups_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
534 void *data ATTRIBUTE_UNUSED
)
539 /* Don't walk into types. */
545 if (TREE_CODE (exp
) != TARGET_EXPR
)
548 cleanup
= TARGET_EXPR_CLEANUP (exp
);
551 cleanup
= build1 (MUST_NOT_THROW_EXPR
, void_type_node
, cleanup
);
552 TARGET_EXPR_CLEANUP (exp
) = cleanup
;
555 /* Keep iterating. */
559 /* Build a throw expression. */
562 build_throw (tree exp
)
566 if (exp
== error_mark_node
)
569 if (processing_template_decl
)
571 current_function_returns_abnormally
= 1;
572 return build_min (THROW_EXPR
, void_type_node
, exp
);
575 if (exp
== null_node
)
576 warning ("throwing NULL, which has integral, not pointer type");
578 if (exp
!= NULL_TREE
)
580 if (!is_admissible_throw_operand (exp
))
581 return error_mark_node
;
585 return error_mark_node
;
587 if (exp
&& decl_is_java_type (TREE_TYPE (exp
), 1))
589 tree fn
= get_identifier ("_Jv_Throw");
590 if (!get_global_value_if_present (fn
, &fn
))
592 /* Declare void _Jv_Throw (void *). */
593 tree tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
594 tmp
= build_function_type (ptr_type_node
, tmp
);
595 fn
= push_throw_library_fn (fn
, tmp
);
597 else if (really_overloaded_fn (fn
))
599 error ("`%D' should never be overloaded", fn
);
600 return error_mark_node
;
602 fn
= OVL_CURRENT (fn
);
603 exp
= build_function_call (fn
, tree_cons (NULL_TREE
, exp
, NULL_TREE
));
611 tree temp_expr
, allocate_expr
;
614 /* The CLEANUP_TYPE is the internal type of a destructor. */
617 tmp
= void_list_node
;
618 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
619 tmp
= build_function_type (void_type_node
, tmp
);
620 cleanup_type
= build_pointer_type (tmp
);
623 fn
= get_identifier ("__cxa_throw");
624 if (!get_global_value_if_present (fn
, &fn
))
626 /* Declare void __cxa_throw (void*, void*, void (*)(void*)). */
627 /* ??? Second argument is supposed to be "std::type_info*". */
628 tmp
= void_list_node
;
629 tmp
= tree_cons (NULL_TREE
, cleanup_type
, tmp
);
630 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
631 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
632 tmp
= build_function_type (void_type_node
, tmp
);
633 fn
= push_throw_library_fn (fn
, tmp
);
636 /* throw expression */
637 /* First, decay it. */
638 exp
= decay_conversion (exp
);
640 /* OK, this is kind of wacky. The standard says that we call
641 terminate when the exception handling mechanism, after
642 completing evaluation of the expression to be thrown but
643 before the exception is caught (_except.throw_), calls a
644 user function that exits via an uncaught exception.
646 So we have to protect the actual initialization of the
647 exception object with terminate(), but evaluate the
648 expression first. Since there could be temps in the
649 expression, we need to handle that, too. We also expand
650 the call to __cxa_allocate_exception first (which doesn't
651 matter, since it can't throw). */
653 /* Allocate the space for the exception. */
654 allocate_expr
= do_allocate_exception (TREE_TYPE (exp
));
655 allocate_expr
= get_target_expr (allocate_expr
);
656 ptr
= TARGET_EXPR_SLOT (allocate_expr
);
657 object
= build1 (NOP_EXPR
, build_pointer_type (TREE_TYPE (exp
)), ptr
);
658 object
= build_indirect_ref (object
, NULL
);
660 elided
= (TREE_CODE (exp
) == TARGET_EXPR
);
662 /* And initialize the exception object. */
663 exp
= build_init (object
, exp
, LOOKUP_ONLYCONVERTING
);
664 if (exp
== error_mark_node
)
666 error (" in thrown expression");
667 return error_mark_node
;
670 /* Pre-evaluate the thrown expression first, since if we allocated
671 the space first we would have to deal with cleaning it up if
672 evaluating this expression throws.
674 The case where EXP the initializer is a call to a constructor or a
675 function returning a class is a bit of a grey area in the
676 standard; it's unclear whether or not it should be allowed to
677 throw. We used to say no, as that allowed us to optimize this
678 case without worrying about deallocating the exception object if
679 it does. But that conflicted with expectations (PR 13944) and the
680 EDG compiler; now we wrap the initialization in a TRY_CATCH_EXPR
681 to call do_free_exception rather than in a MUST_NOT_THROW_EXPR,
684 Note that we don't check the return value from stabilize_init
685 because it will only return false in cases where elided is true,
686 and therefore we don't need to work around the failure to
688 temp_expr
= NULL_TREE
;
689 stabilize_init (exp
, &temp_expr
);
692 exp
= build2 (TRY_CATCH_EXPR
, void_type_node
, exp
,
693 do_free_exception (ptr
));
695 exp
= build1 (MUST_NOT_THROW_EXPR
, void_type_node
, exp
);
697 /* Prepend the allocation. */
698 exp
= build2 (COMPOUND_EXPR
, TREE_TYPE (exp
), allocate_expr
, exp
);
701 /* Prepend the calculation of the throw expression. Also, force
702 any cleanups from the expression to be evaluated here so that
703 we don't have to do them during unwinding. But first wrap
704 them in MUST_NOT_THROW_EXPR, since they are run after the
705 exception object is initialized. */
706 walk_tree_without_duplicates (&temp_expr
, wrap_cleanups_r
, 0);
707 exp
= build2 (COMPOUND_EXPR
, TREE_TYPE (exp
), temp_expr
, exp
);
708 exp
= build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
);
711 throw_type
= build_eh_type_type (prepare_eh_type (TREE_TYPE (object
)));
713 if (TYPE_HAS_DESTRUCTOR (TREE_TYPE (object
)))
715 cleanup
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (object
)),
716 complete_dtor_identifier
, 0);
717 cleanup
= BASELINK_FUNCTIONS (cleanup
);
719 cxx_mark_addressable (cleanup
);
720 /* Pretend it's a normal function. */
721 cleanup
= build1 (ADDR_EXPR
, cleanup_type
, cleanup
);
724 cleanup
= build_int_cst (cleanup_type
, 0);
726 tmp
= tree_cons (NULL_TREE
, cleanup
, NULL_TREE
);
727 tmp
= tree_cons (NULL_TREE
, throw_type
, tmp
);
728 tmp
= tree_cons (NULL_TREE
, ptr
, tmp
);
729 /* ??? Indicate that this function call throws throw_type. */
730 tmp
= build_function_call (fn
, tmp
);
732 /* Tack on the initialization stuff. */
733 exp
= build2 (COMPOUND_EXPR
, TREE_TYPE (tmp
), exp
, tmp
);
737 /* Rethrow current exception. */
739 tree fn
= get_identifier ("__cxa_rethrow");
740 if (!get_global_value_if_present (fn
, &fn
))
742 /* Declare void __cxa_rethrow (void). */
743 fn
= push_throw_library_fn
744 (fn
, build_function_type (void_type_node
, void_list_node
));
747 /* ??? Indicate that this function call allows exceptions of the type
748 of the enclosing catch block (if known). */
749 exp
= build_function_call (fn
, NULL_TREE
);
752 exp
= build1 (THROW_EXPR
, void_type_node
, exp
);
757 /* Make sure TYPE is complete, pointer to complete, reference to
758 complete, or pointer to cv void. Issue diagnostic on failure.
759 Return the zero on failure and nonzero on success. FROM can be
760 the expr or decl from whence TYPE came, if available. */
763 complete_ptr_ref_or_void_ptr_p (tree type
, tree from
)
767 /* Check complete. */
768 type
= complete_type_or_else (type
, from
);
772 /* Or a pointer or ref to one, or cv void *. */
773 is_ptr
= TREE_CODE (type
) == POINTER_TYPE
;
774 if (is_ptr
|| TREE_CODE (type
) == REFERENCE_TYPE
)
776 tree core
= TREE_TYPE (type
);
778 if (is_ptr
&& VOID_TYPE_P (core
))
780 else if (!complete_type_or_else (core
, from
))
786 /* Return truth-value if EXPRESSION is admissible in throw-expression,
787 i.e. if it is not of incomplete type or a pointer/reference to such
788 a type or of an abstract class type. */
791 is_admissible_throw_operand (tree expr
)
793 tree type
= TREE_TYPE (expr
);
795 /* 15.1/4 [...] The type of the throw-expression shall not be an
796 incomplete type, or a pointer or a reference to an incomplete
797 type, other than void*, const void*, volatile void*, or
798 const volatile void*. Except for these restriction and the
799 restrictions on type matching mentioned in 15.3, the operand
800 of throw is treated exactly as a function argument in a call
801 (5.2.2) or the operand of a return statement. */
802 if (!complete_ptr_ref_or_void_ptr_p (type
, expr
))
805 /* 10.4/3 An abstract class shall not be used as a parameter type,
806 as a function return type or as type of an explicit
808 else if (CLASS_TYPE_P (type
) && CLASSTYPE_PURE_VIRTUALS (type
))
810 error ("expression '%E' of abstract class type '%T' cannot be used in throw-expression", expr
, type
);
817 /* Returns nonzero if FN is a declaration of a standard C library
818 function which is known not to throw.
820 [lib.res.on.exception.handling]: None of the functions from the
821 Standard C library shall report an error by throwing an
822 exception, unless it calls a program-supplied function that
823 throws an exception. */
828 nothrow_libfn_p (tree fn
)
833 && DECL_EXTERNAL (fn
)
834 && DECL_NAMESPACE_SCOPE_P (fn
)
835 && DECL_EXTERN_C_P (fn
))
838 /* Can't be a C library function. */
841 /* Being a C library function, DECL_ASSEMBLER_NAME == DECL_NAME
842 unless the system headers are playing rename tricks, and if
843 they are, we don't want to be confused by them. */
845 return !!libc_name_p (IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
848 /* Returns nonzero if an exception of type FROM will be caught by a
849 handler for type TO, as per [except.handle]. */
852 can_convert_eh (tree to
, tree from
)
854 to
= non_reference (to
);
855 from
= non_reference (from
);
857 if (TREE_CODE (to
) == POINTER_TYPE
&& TREE_CODE (from
) == POINTER_TYPE
)
860 from
= TREE_TYPE (from
);
862 if (! at_least_as_qualified_p (to
, from
))
865 if (TREE_CODE (to
) == VOID_TYPE
)
868 /* Else fall through. */
871 if (CLASS_TYPE_P (to
) && CLASS_TYPE_P (from
)
872 && PUBLICLY_UNIQUELY_DERIVED_P (to
, from
))
878 /* Check whether any of the handlers in I are shadowed by another handler
879 accepting TYPE. Note that the shadowing may not be complete; even if
880 an exception of type B would be caught by a handler for A, there could
881 be a derived class C for which A is an ambiguous base but B is not, so
882 the handler for B would catch an exception of type C. */
885 check_handlers_1 (tree master
, tree_stmt_iterator i
)
887 tree type
= TREE_TYPE (master
);
889 for (; !tsi_end_p (i
); tsi_next (&i
))
891 tree handler
= tsi_stmt (i
);
892 if (TREE_TYPE (handler
) && can_convert_eh (type
, TREE_TYPE (handler
)))
894 warning ("%Hexception of type `%T' will be caught",
895 EXPR_LOCUS (handler
), TREE_TYPE (handler
));
896 warning ("%H by earlier handler for `%T'",
897 EXPR_LOCUS (master
), type
);
903 /* Given a STATEMENT_LIST of HANDLERs, make sure that they're OK. */
906 check_handlers (tree handlers
)
908 tree_stmt_iterator i
;
910 /* If we don't have a STATEMENT_LIST, then we've just got one
911 handler, and thus nothing to warn about. */
912 if (TREE_CODE (handlers
) != STATEMENT_LIST
)
915 i
= tsi_start (handlers
);
919 tree handler
= tsi_stmt (i
);
922 /* No more handlers; nothing to shadow. */
925 if (TREE_TYPE (handler
) == NULL_TREE
)
926 pedwarn ("%H`...' handler must be the last handler for"
927 " its try block", EXPR_LOCUS (handler
));
929 check_handlers_1 (handler
, i
);