Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/rtti.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* RunTime Type Identification | 1 /* RunTime Type Identification |
2 Copyright (C) 1995-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1995-2018 Free Software Foundation, Inc. |
3 Mostly written by Jason Merrill (jason@cygnus.com). | 3 Mostly written by Jason Merrill (jason@cygnus.com). |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
204 | 204 |
205 /* The offset-to-top field is at index -2 from the vptr. */ | 205 /* The offset-to-top field is at index -2 from the vptr. */ |
206 index = build_int_cst (NULL_TREE, | 206 index = build_int_cst (NULL_TREE, |
207 -2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE); | 207 -2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE); |
208 | 208 |
209 offset = build_vtbl_ref (cp_build_indirect_ref (exp, RO_NULL, | 209 offset = build_vtbl_ref (cp_build_fold_indirect_ref (exp), |
210 tf_warning_or_error), | |
211 index); | 210 index); |
212 | 211 |
213 type = cp_build_qualified_type (ptr_type_node, | 212 type = cp_build_qualified_type (ptr_type_node, |
214 cp_type_quals (TREE_TYPE (exp))); | 213 cp_type_quals (TREE_TYPE (exp))); |
215 return fold_build_pointer_plus (exp, offset); | 214 return fold_build_pointer_plus (exp, offset); |
272 return error_mark_node; | 271 return error_mark_node; |
273 | 272 |
274 exp = resolve_nondeduced_context (exp, complain); | 273 exp = resolve_nondeduced_context (exp, complain); |
275 | 274 |
276 /* peel back references, so they match. */ | 275 /* peel back references, so they match. */ |
277 type = non_reference (TREE_TYPE (exp)); | 276 type = non_reference (unlowered_expr_type (exp)); |
278 | 277 |
279 /* Peel off cv qualifiers. */ | 278 /* Peel off cv qualifiers. */ |
280 type = TYPE_MAIN_VARIANT (type); | 279 type = TYPE_MAIN_VARIANT (type); |
281 | 280 |
282 /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics. */ | 281 /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics. */ |
301 } | 300 } |
302 else | 301 else |
303 /* Otherwise return the type_info for the static type of the expr. */ | 302 /* Otherwise return the type_info for the static type of the expr. */ |
304 t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type)); | 303 t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type)); |
305 | 304 |
306 return cp_build_indirect_ref (t, RO_NULL, complain); | 305 return cp_build_fold_indirect_ref (t); |
307 } | 306 } |
308 | 307 |
309 static bool | 308 static bool |
310 typeid_ok_p (void) | 309 typeid_ok_p (void) |
311 { | 310 { |
316 } | 315 } |
317 | 316 |
318 if (!COMPLETE_TYPE_P (const_type_info_type_node)) | 317 if (!COMPLETE_TYPE_P (const_type_info_type_node)) |
319 { | 318 { |
320 gcc_rich_location richloc (input_location); | 319 gcc_rich_location richloc (input_location); |
321 maybe_add_include_fixit (&richloc, "<typeinfo>"); | 320 maybe_add_include_fixit (&richloc, "<typeinfo>", false); |
322 error_at_rich_loc (&richloc, | 321 error_at (&richloc, |
323 "must %<#include <typeinfo>%> before using" | 322 "must %<#include <typeinfo>%> before using" |
324 " %<typeid%>"); | 323 " %<typeid%>"); |
325 | 324 |
326 return false; | 325 return false; |
327 } | 326 } |
328 | 327 |
329 tree pseudo = TYPE_MAIN_VARIANT (get_tinfo_desc (TK_TYPE_INFO_TYPE)->type); | 328 tree pseudo = TYPE_MAIN_VARIANT (get_tinfo_desc (TK_TYPE_INFO_TYPE)->type); |
363 /* So we need to look into the vtable of the type of exp. | 362 /* So we need to look into the vtable of the type of exp. |
364 Make sure it isn't a null lvalue. */ | 363 Make sure it isn't a null lvalue. */ |
365 exp = cp_build_addr_expr (exp, complain); | 364 exp = cp_build_addr_expr (exp, complain); |
366 exp = save_expr (exp); | 365 exp = save_expr (exp); |
367 cond = cp_convert (boolean_type_node, exp, complain); | 366 cond = cp_convert (boolean_type_node, exp, complain); |
368 exp = cp_build_indirect_ref (exp, RO_NULL, complain); | 367 exp = cp_build_fold_indirect_ref (exp); |
369 } | 368 } |
370 | 369 |
371 exp = get_tinfo_decl_dynamic (exp, complain); | 370 exp = get_tinfo_decl_dynamic (exp, complain); |
372 | 371 |
373 if (exp == error_mark_node) | 372 if (exp == error_mark_node) |
527 type = complete_type_or_maybe_complain (type, NULL_TREE, complain); | 526 type = complete_type_or_maybe_complain (type, NULL_TREE, complain); |
528 | 527 |
529 if (!type) | 528 if (!type) |
530 return error_mark_node; | 529 return error_mark_node; |
531 | 530 |
532 return cp_build_indirect_ref (get_tinfo_ptr (type), RO_NULL, complain); | 531 return cp_build_fold_indirect_ref (get_tinfo_ptr (type)); |
533 } | 532 } |
534 | 533 |
535 /* Check whether TEST is null before returning RESULT. If TEST is used in | 534 /* Check whether TEST is null before returning RESULT. If TEST is used in |
536 RESULT, it must have previously had a save_expr applied to it. */ | 535 RESULT, it must have previously had a save_expr applied to it. */ |
537 | 536 |
615 } | 614 } |
616 } | 615 } |
617 else | 616 else |
618 { | 617 { |
619 expr = mark_lvalue_use (expr); | 618 expr = mark_lvalue_use (expr); |
620 | 619 exprtype = TREE_TYPE (expr); |
621 exprtype = build_reference_type (TREE_TYPE (expr)); | |
622 | 620 |
623 /* T is a reference type, v shall be an lvalue of a complete class | 621 /* T is a reference type, v shall be an lvalue of a complete class |
624 type, and the result is an lvalue of the type referred to by T. */ | 622 type, and the result is an lvalue of the type referred to by T. */ |
625 | 623 if (! MAYBE_CLASS_TYPE_P (exprtype)) |
626 if (! MAYBE_CLASS_TYPE_P (TREE_TYPE (exprtype))) | |
627 { | 624 { |
628 errstr = _("source is not of class type"); | 625 errstr = _("source is not of class type"); |
629 goto fail; | 626 goto fail; |
630 } | 627 } |
631 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (exprtype)))) | 628 if (!COMPLETE_TYPE_P (complete_type (exprtype))) |
632 { | 629 { |
633 errstr = _("source is of incomplete class type"); | 630 errstr = _("source is of incomplete class type"); |
634 goto fail; | 631 goto fail; |
635 } | 632 } |
633 | |
634 exprtype = cp_build_reference_type (exprtype, !lvalue_p (expr)); | |
636 } | 635 } |
637 | 636 |
638 /* The dynamic_cast operator shall not cast away constness. */ | 637 /* The dynamic_cast operator shall not cast away constness. */ |
639 if (!at_least_as_qualified_p (TREE_TYPE (type), | 638 if (!at_least_as_qualified_p (TREE_TYPE (type), |
640 TREE_TYPE (exprtype))) | 639 TREE_TYPE (exprtype))) |