@@ -525,7 +525,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
525
525
526
526
let value =
527
527
if result_type. is_signed ( self . cx ) {
528
- self . context . new_bitcast ( None , value, typ)
528
+ self . context . new_cast ( None , value, typ)
529
529
}
530
530
else {
531
531
value
@@ -689,7 +689,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
689
689
} ,
690
690
} ;
691
691
692
- self . context . new_bitcast ( None , result, result_type)
692
+ self . context . new_cast ( None , result, result_type)
693
693
}
694
694
695
695
fn count_leading_zeroes ( & self , width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -740,6 +740,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
740
740
let not_low = self . context . new_unary_op ( None , UnaryOp :: LogicalNegate , self . u64_type , low) ;
741
741
let not_low_and_not_high = not_low & not_high;
742
742
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 ) ;
743
748
744
749
let res = self . context . new_array_access ( None , result, index) ;
745
750
@@ -763,7 +768,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
763
768
let arg =
764
769
if result_type. is_signed ( self . cx ) {
765
770
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)
767
772
}
768
773
else {
769
774
arg
@@ -815,10 +820,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
815
820
let not_high = self . context . new_unary_op ( None , UnaryOp :: LogicalNegate , self . u64_type , high) ;
816
821
let not_low_and_not_high = not_low & not_high;
817
822
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 ) ;
818
828
819
829
let res = self . context . new_array_access ( None , result, index) ;
820
830
821
- return self . context . new_bitcast ( None , res, result_type) ;
831
+ return self . context . new_cast ( None , res, result_type) ;
822
832
}
823
833
else {
824
834
unimplemented ! ( "count_trailing_zeroes for {:?}" , arg_type) ;
@@ -832,7 +842,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
832
842
arg
833
843
} ;
834
844
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)
836
846
}
837
847
838
848
fn int_width ( & self , typ : Type < ' gcc > ) -> i64 {
@@ -846,7 +856,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
846
856
847
857
let value =
848
858
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)
850
860
}
851
861
else {
852
862
value
@@ -862,7 +872,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
862
872
let low = self . context . new_cast ( None , value, self . cx . ulonglong_type ) ;
863
873
let low = self . context . new_call ( None , popcount, & [ low] ) ;
864
874
let res = high + low;
865
- return self . context . new_bitcast ( None , res, result_type) ;
875
+ return self . context . new_cast ( None , res, result_type) ;
866
876
}
867
877
868
878
// First step.
@@ -887,7 +897,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
887
897
let value = left + right;
888
898
889
899
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) ;
891
901
}
892
902
893
903
// Fourth step.
@@ -898,7 +908,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
898
908
let value = left + right;
899
909
900
910
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) ;
902
912
}
903
913
904
914
// Fifth step.
@@ -909,7 +919,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
909
919
let value = left + right;
910
920
911
921
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) ;
913
923
}
914
924
915
925
// Sixth step.
@@ -919,7 +929,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
919
929
let right = shifted & mask;
920
930
let value = left + right;
921
931
922
- self . context . new_bitcast ( None , value, result_type)
932
+ self . context . new_cast ( None , value, result_type)
923
933
}
924
934
925
935
// Algorithm from: https://blog.regehr.org/archives/1063
0 commit comments