@@ -525,7 +525,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
525525
526526 let value =
527527 if result_type. is_signed ( self . cx ) {
528- self . context . new_bitcast ( None , value, typ)
528+ self . context . new_cast ( None , value, typ)
529529 }
530530 else {
531531 value
@@ -689,7 +689,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
689689 } ,
690690 } ;
691691
692- self . context . new_bitcast ( None , result, result_type)
692+ self . context . new_cast ( None , result, result_type)
693693 }
694694
695695 fn count_leading_zeroes ( & self , width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -740,6 +740,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
740740 let not_low = self . context . new_unary_op ( None , UnaryOp :: LogicalNegate , self . u64_type , low) ;
741741 let not_low_and_not_high = not_low & not_high;
742742 let index = not_high + not_low_and_not_high;
743+ // NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
744+ // gcc.
745+ // TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
746+ // compilation stage.
747+ let index = self . context . new_cast ( None , index, self . i32_type ) ;
743748
744749 let res = self . context . new_array_access ( None , result, index) ;
745750
@@ -763,7 +768,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
763768 let arg =
764769 if result_type. is_signed ( self . cx ) {
765770 let new_type = result_type. to_unsigned ( self . cx ) ;
766- self . context . new_bitcast ( None , arg, new_type)
771+ self . context . new_cast ( None , arg, new_type)
767772 }
768773 else {
769774 arg
@@ -815,10 +820,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
815820 let not_high = self . context . new_unary_op ( None , UnaryOp :: LogicalNegate , self . u64_type , high) ;
816821 let not_low_and_not_high = not_low & not_high;
817822 let index = not_low + not_low_and_not_high;
823+ // NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
824+ // gcc.
825+ // TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
826+ // compilation stage.
827+ let index = self . context . new_cast ( None , index, self . i32_type ) ;
818828
819829 let res = self . context . new_array_access ( None , result, index) ;
820830
821- return self . context . new_bitcast ( None , res, result_type) ;
831+ return self . context . new_cast ( None , res, result_type) ;
822832 }
823833 else {
824834 unimplemented ! ( "count_trailing_zeroes for {:?}" , arg_type) ;
@@ -832,7 +842,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
832842 arg
833843 } ;
834844 let res = self . context . new_call ( None , count_trailing_zeroes, & [ arg] ) ;
835- self . context . new_bitcast ( None , res, result_type)
845+ self . context . new_cast ( None , res, result_type)
836846 }
837847
838848 fn int_width ( & self , typ : Type < ' gcc > ) -> i64 {
@@ -846,7 +856,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
846856
847857 let value =
848858 if result_type. is_signed ( self . cx ) {
849- self . context . new_bitcast ( None , value, value_type)
859+ self . context . new_cast ( None , value, value_type)
850860 }
851861 else {
852862 value
@@ -862,7 +872,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
862872 let low = self . context . new_cast ( None , value, self . cx . ulonglong_type ) ;
863873 let low = self . context . new_call ( None , popcount, & [ low] ) ;
864874 let res = high + low;
865- return self . context . new_bitcast ( None , res, result_type) ;
875+ return self . context . new_cast ( None , res, result_type) ;
866876 }
867877
868878 // First step.
@@ -887,7 +897,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
887897 let value = left + right;
888898
889899 if value_type. is_u8 ( & self . cx ) {
890- return self . context . new_bitcast ( None , value, result_type) ;
900+ return self . context . new_cast ( None , value, result_type) ;
891901 }
892902
893903 // Fourth step.
@@ -898,7 +908,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
898908 let value = left + right;
899909
900910 if value_type. is_u16 ( & self . cx ) {
901- return self . context . new_bitcast ( None , value, result_type) ;
911+ return self . context . new_cast ( None , value, result_type) ;
902912 }
903913
904914 // Fifth step.
@@ -909,7 +919,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
909919 let value = left + right;
910920
911921 if value_type. is_u32 ( & self . cx ) {
912- return self . context . new_bitcast ( None , value, result_type) ;
922+ return self . context . new_cast ( None , value, result_type) ;
913923 }
914924
915925 // Sixth step.
@@ -919,7 +929,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
919929 let right = shifted & mask;
920930 let value = left + right;
921931
922- self . context . new_bitcast ( None , value, result_type)
932+ self . context . new_cast ( None , value, result_type)
923933 }
924934
925935 // Algorithm from: https://blog.regehr.org/archives/1063
0 commit comments