comparison gcc/convert.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 /* Utility routines for data type conversion for GCC. 1 /* Utility routines for data type conversion for GCC.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. 2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
469 ARG1 is of a signed type, we have to do 469 ARG1 is of a signed type, we have to do
470 PLUS_EXPR, MINUS_EXPR or MULT_EXPR in an unsigned 470 PLUS_EXPR, MINUS_EXPR or MULT_EXPR in an unsigned
471 type in case the operation in outprec precision 471 type in case the operation in outprec precision
472 could overflow. Otherwise, we would introduce 472 could overflow. Otherwise, we would introduce
473 signed-overflow undefinedness. */ 473 signed-overflow undefinedness. */
474 || ((!TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)) 474 || ((!(INTEGRAL_TYPE_P (TREE_TYPE (arg0))
475 || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))) 475 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)))
476 || !(INTEGRAL_TYPE_P (TREE_TYPE (arg1))
477 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))))
476 && ((TYPE_PRECISION (TREE_TYPE (arg0)) * 2u 478 && ((TYPE_PRECISION (TREE_TYPE (arg0)) * 2u
477 > outprec) 479 > outprec)
478 || (TYPE_PRECISION (TREE_TYPE (arg1)) * 2u 480 || (TYPE_PRECISION (TREE_TYPE (arg1)) * 2u
479 > outprec)) 481 > outprec))
480 && (ex_form == PLUS_EXPR 482 && (ex_form == PLUS_EXPR
552 tree fn = 0; 554 tree fn = 0;
553 555
554 switch (fcode) 556 switch (fcode)
555 { 557 {
556 CASE_FLT_FN (BUILT_IN_CEIL): 558 CASE_FLT_FN (BUILT_IN_CEIL):
559 CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
557 /* Only convert in ISO C99 mode. */ 560 /* Only convert in ISO C99 mode. */
558 if (!targetm.libc_has_function (function_c99_misc)) 561 if (!targetm.libc_has_function (function_c99_misc))
559 break; 562 break;
560 if (outprec < TYPE_PRECISION (integer_type_node) 563 if (outprec < TYPE_PRECISION (integer_type_node)
561 || (outprec == TYPE_PRECISION (integer_type_node) 564 || (outprec == TYPE_PRECISION (integer_type_node)
568 && !TYPE_UNSIGNED (type)) 571 && !TYPE_UNSIGNED (type))
569 fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL); 572 fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL);
570 break; 573 break;
571 574
572 CASE_FLT_FN (BUILT_IN_FLOOR): 575 CASE_FLT_FN (BUILT_IN_FLOOR):
576 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
573 /* Only convert in ISO C99 mode. */ 577 /* Only convert in ISO C99 mode. */
574 if (!targetm.libc_has_function (function_c99_misc)) 578 if (!targetm.libc_has_function (function_c99_misc))
575 break; 579 break;
576 if (outprec < TYPE_PRECISION (integer_type_node) 580 if (outprec < TYPE_PRECISION (integer_type_node)
577 || (outprec == TYPE_PRECISION (integer_type_node) 581 || (outprec == TYPE_PRECISION (integer_type_node)
584 && !TYPE_UNSIGNED (type)) 588 && !TYPE_UNSIGNED (type))
585 fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR); 589 fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR);
586 break; 590 break;
587 591
588 CASE_FLT_FN (BUILT_IN_ROUND): 592 CASE_FLT_FN (BUILT_IN_ROUND):
593 CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
589 /* Only convert in ISO C99 mode and with -fno-math-errno. */ 594 /* Only convert in ISO C99 mode and with -fno-math-errno. */
590 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math) 595 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
591 break; 596 break;
592 if (outprec < TYPE_PRECISION (integer_type_node) 597 if (outprec < TYPE_PRECISION (integer_type_node)
593 || (outprec == TYPE_PRECISION (integer_type_node) 598 || (outprec == TYPE_PRECISION (integer_type_node)
600 && !TYPE_UNSIGNED (type)) 605 && !TYPE_UNSIGNED (type))
601 fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND); 606 fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND);
602 break; 607 break;
603 608
604 CASE_FLT_FN (BUILT_IN_NEARBYINT): 609 CASE_FLT_FN (BUILT_IN_NEARBYINT):
610 CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
605 /* Only convert nearbyint* if we can ignore math exceptions. */ 611 /* Only convert nearbyint* if we can ignore math exceptions. */
606 if (flag_trapping_math) 612 if (flag_trapping_math)
607 break; 613 break;
608 gcc_fallthrough (); 614 gcc_fallthrough ();
609 CASE_FLT_FN (BUILT_IN_RINT): 615 CASE_FLT_FN (BUILT_IN_RINT):
616 CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
610 /* Only convert in ISO C99 mode and with -fno-math-errno. */ 617 /* Only convert in ISO C99 mode and with -fno-math-errno. */
611 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math) 618 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
612 break; 619 break;
613 if (outprec < TYPE_PRECISION (integer_type_node) 620 if (outprec < TYPE_PRECISION (integer_type_node)
614 || (outprec == TYPE_PRECISION (integer_type_node) 621 || (outprec == TYPE_PRECISION (integer_type_node)
621 && !TYPE_UNSIGNED (type)) 628 && !TYPE_UNSIGNED (type))
622 fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT); 629 fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT);
623 break; 630 break;
624 631
625 CASE_FLT_FN (BUILT_IN_TRUNC): 632 CASE_FLT_FN (BUILT_IN_TRUNC):
633 CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
626 return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0), dofold); 634 return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0), dofold);
627 635
628 default: 636 default:
629 break; 637 break;
630 } 638 }
669 677
670 switch (TREE_CODE (intype)) 678 switch (TREE_CODE (intype))
671 { 679 {
672 case POINTER_TYPE: 680 case POINTER_TYPE:
673 case REFERENCE_TYPE: 681 case REFERENCE_TYPE:
674 if (integer_zerop (expr)) 682 if (integer_zerop (expr) && !TREE_OVERFLOW (expr))
675 return build_int_cst (type, 0); 683 return build_int_cst (type, 0);
676 684
677 /* Convert to an unsigned integer of the correct width first, and from 685 /* Convert to an unsigned integer of the correct width first, and from
678 there widen/truncate to the required type. Some targets support the 686 there widen/truncate to the required type. Some targets support the
679 coexistence of multiple valid pointer sizes, so fetch the one we need 687 coexistence of multiple valid pointer sizes, so fetch the one we need
729 /* If TYPE is an enumeral type or a type with a precision less 737 /* If TYPE is an enumeral type or a type with a precision less
730 than the number of bits in its mode, do the conversion to the 738 than the number of bits in its mode, do the conversion to the
731 type corresponding to its mode, then do a nop conversion 739 type corresponding to its mode, then do a nop conversion
732 to TYPE. */ 740 to TYPE. */
733 else if (TREE_CODE (type) == ENUMERAL_TYPE 741 else if (TREE_CODE (type) == ENUMERAL_TYPE
734 || outprec != GET_MODE_PRECISION (TYPE_MODE (type))) 742 || maybe_ne (outprec, GET_MODE_PRECISION (TYPE_MODE (type))))
735 { 743 {
736 expr = convert (lang_hooks.types.type_for_mode 744 expr
737 (TYPE_MODE (type), TYPE_UNSIGNED (type)), expr); 745 = convert_to_integer_1 (lang_hooks.types.type_for_mode
746 (TYPE_MODE (type), TYPE_UNSIGNED (type)),
747 expr, dofold);
738 return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr); 748 return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr);
739 } 749 }
740 750
741 /* Here detect when we can distribute the truncation down past some 751 /* Here detect when we can distribute the truncation down past some
742 arithmetic. For example, if adding two longs and converting to an 752 arithmetic. For example, if adding two longs and converting to an
914 convert (typex, 924 convert (typex,
915 TREE_OPERAND (expr, 0)))); 925 TREE_OPERAND (expr, 0))));
916 } 926 }
917 927
918 CASE_CONVERT: 928 CASE_CONVERT:
919 /* Don't introduce a "can't convert between vector values of 929 {
920 different size" error. */ 930 tree argtype = TREE_TYPE (TREE_OPERAND (expr, 0));
921 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == VECTOR_TYPE 931 /* Don't introduce a "can't convert between vector values
922 && (GET_MODE_SIZE (TYPE_MODE 932 of different size" error. */
923 (TREE_TYPE (TREE_OPERAND (expr, 0)))) 933 if (TREE_CODE (argtype) == VECTOR_TYPE
924 != GET_MODE_SIZE (TYPE_MODE (type)))) 934 && maybe_ne (GET_MODE_SIZE (TYPE_MODE (argtype)),
925 break; 935 GET_MODE_SIZE (TYPE_MODE (type))))
936 break;
937 }
926 /* If truncating after truncating, might as well do all at once. 938 /* If truncating after truncating, might as well do all at once.
927 If truncating after extending, we may get rid of wasted work. */ 939 If truncating after extending, we may get rid of wasted work. */
928 return convert (type, get_unwidened (TREE_OPERAND (expr, 0), type)); 940 return convert (type, get_unwidened (TREE_OPERAND (expr, 0), type));
929 941
930 case COND_EXPR: 942 case COND_EXPR: