Mercurial > hg > CbC > CbC_gcc
comparison gcc/convert.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
28 #include "coretypes.h" | 28 #include "coretypes.h" |
29 #include "tm.h" | 29 #include "tm.h" |
30 #include "tree.h" | 30 #include "tree.h" |
31 #include "flags.h" | 31 #include "flags.h" |
32 #include "convert.h" | 32 #include "convert.h" |
33 #include "toplev.h" | 33 #include "diagnostic-core.h" |
34 #include "langhooks.h" | 34 #include "langhooks.h" |
35 | 35 |
36 /* Convert EXPR to some pointer or reference type TYPE. | 36 /* Convert EXPR to some pointer or reference type TYPE. |
37 EXPR must be pointer, reference, integer, enumeral, or literal zero; | 37 EXPR must be pointer, reference, integer, enumeral, or literal zero; |
38 in other cases error is called. */ | 38 in other cases error is called. */ |
44 if (TREE_TYPE (expr) == type) | 44 if (TREE_TYPE (expr) == type) |
45 return expr; | 45 return expr; |
46 | 46 |
47 /* Propagate overflow to the NULL pointer. */ | 47 /* Propagate overflow to the NULL pointer. */ |
48 if (integer_zerop (expr)) | 48 if (integer_zerop (expr)) |
49 return force_fit_type_double (type, 0, 0, 0, TREE_OVERFLOW (expr)); | 49 return force_fit_type_double (type, double_int_zero, 0, |
50 TREE_OVERFLOW (expr)); | |
50 | 51 |
51 switch (TREE_CODE (TREE_TYPE (expr))) | 52 switch (TREE_CODE (TREE_TYPE (expr))) |
52 { | 53 { |
53 case POINTER_TYPE: | 54 case POINTER_TYPE: |
54 case REFERENCE_TYPE: | 55 case REFERENCE_TYPE: |
765 || ex_form == LROTATE_EXPR | 766 || ex_form == LROTATE_EXPR |
766 || ex_form == RROTATE_EXPR)) | 767 || ex_form == RROTATE_EXPR)) |
767 || ex_form == LSHIFT_EXPR | 768 || ex_form == LSHIFT_EXPR |
768 /* If we have !flag_wrapv, and either ARG0 or | 769 /* If we have !flag_wrapv, and either ARG0 or |
769 ARG1 is of a signed type, we have to do | 770 ARG1 is of a signed type, we have to do |
770 PLUS_EXPR or MINUS_EXPR in an unsigned | 771 PLUS_EXPR, MINUS_EXPR or MULT_EXPR in an unsigned |
771 type. Otherwise, we would introduce | 772 type in case the operation in outprec precision |
773 could overflow. Otherwise, we would introduce | |
772 signed-overflow undefinedness. */ | 774 signed-overflow undefinedness. */ |
773 || ((!TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)) | 775 || ((!TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)) |
774 || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))) | 776 || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))) |
777 && ((TYPE_PRECISION (TREE_TYPE (arg0)) * 2u | |
778 > outprec) | |
779 || (TYPE_PRECISION (TREE_TYPE (arg1)) * 2u | |
780 > outprec)) | |
775 && (ex_form == PLUS_EXPR | 781 && (ex_form == PLUS_EXPR |
776 || ex_form == MINUS_EXPR))) | 782 || ex_form == MINUS_EXPR |
783 || ex_form == MULT_EXPR))) | |
777 typex = unsigned_type_for (typex); | 784 typex = unsigned_type_for (typex); |
778 else | 785 else |
779 typex = signed_type_for (typex); | 786 typex = signed_type_for (typex); |
780 return convert (type, | 787 return convert (type, |
781 fold_build2 (ex_form, typex, | 788 fold_build2 (ex_form, typex, |
789 case NEGATE_EXPR: | 796 case NEGATE_EXPR: |
790 case BIT_NOT_EXPR: | 797 case BIT_NOT_EXPR: |
791 /* This is not correct for ABS_EXPR, | 798 /* This is not correct for ABS_EXPR, |
792 since we must test the sign before truncation. */ | 799 since we must test the sign before truncation. */ |
793 { | 800 { |
794 tree typex; | 801 tree typex = unsigned_type_for (type); |
795 | |
796 /* Don't do unsigned arithmetic where signed was wanted, | |
797 or vice versa. */ | |
798 if (TYPE_UNSIGNED (TREE_TYPE (expr))) | |
799 typex = unsigned_type_for (type); | |
800 else | |
801 typex = signed_type_for (type); | |
802 return convert (type, | 802 return convert (type, |
803 fold_build1 (ex_form, typex, | 803 fold_build1 (ex_form, typex, |
804 convert (typex, | 804 convert (typex, |
805 TREE_OPERAND (expr, 0)))); | 805 TREE_OPERAND (expr, 0)))); |
806 } | 806 } |
847 TREE_TYPE (TREE_TYPE (expr)), expr)); | 847 TREE_TYPE (TREE_TYPE (expr)), expr)); |
848 | 848 |
849 case VECTOR_TYPE: | 849 case VECTOR_TYPE: |
850 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr)))) | 850 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr)))) |
851 { | 851 { |
852 error ("can't convert between vector values of different size"); | 852 error ("can%'t convert between vector values of different size"); |
853 return error_mark_node; | 853 return error_mark_node; |
854 } | 854 } |
855 return build1 (VIEW_CONVERT_EXPR, type, expr); | 855 return build1 (VIEW_CONVERT_EXPR, type, expr); |
856 | 856 |
857 default: | 857 default: |
923 { | 923 { |
924 case INTEGER_TYPE: | 924 case INTEGER_TYPE: |
925 case VECTOR_TYPE: | 925 case VECTOR_TYPE: |
926 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr)))) | 926 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr)))) |
927 { | 927 { |
928 error ("can't convert between vector values of different size"); | 928 error ("can%'t convert between vector values of different size"); |
929 return error_mark_node; | 929 return error_mark_node; |
930 } | 930 } |
931 return build1 (VIEW_CONVERT_EXPR, type, expr); | 931 return build1 (VIEW_CONVERT_EXPR, type, expr); |
932 | 932 |
933 default: | 933 default: |
934 error ("can't convert value to a vector"); | 934 error ("can%'t convert value to a vector"); |
935 return error_mark_node; | 935 return error_mark_node; |
936 } | 936 } |
937 } | 937 } |
938 | 938 |
939 /* Convert EXPR to some fixed-point type TYPE. | 939 /* Convert EXPR to some fixed-point type TYPE. |