@@ -3050,34 +3050,6 @@ TEST(APIntTest, smul_ov) {
3050
3050
}
3051
3051
3052
3052
TEST (APIntTest, sfloordiv_ov) {
3053
- // test negative quotient
3054
- {
3055
- APInt divisor (32 , -3 , true );
3056
- APInt dividend (32 , 2 , true );
3057
- bool Overflow = false ;
3058
- auto quotient = divisor.sfloordiv_ov (dividend, Overflow);
3059
- EXPECT_FALSE (Overflow);
3060
- EXPECT_EQ (-2 , quotient.getSExtValue ());
3061
- }
3062
- // test positive quotient
3063
- {
3064
- APInt divisor (32 , 3 , true );
3065
- APInt dividend (32 , 2 , true );
3066
- bool Overflow = false ;
3067
- auto quotient = divisor.sfloordiv_ov (dividend, Overflow);
3068
- EXPECT_FALSE (Overflow);
3069
- EXPECT_EQ (1 , quotient.getSExtValue ());
3070
- }
3071
- // int8 test overflow
3072
- {
3073
- using IntTy = int8_t ;
3074
- APInt divisor (8 * sizeof (IntTy), std::numeric_limits<IntTy>::lowest (),
3075
- true );
3076
- APInt dividend (8 * sizeof (IntTy), IntTy (-1 ), true );
3077
- bool Overflow = false ;
3078
- (void )divisor.sfloordiv_ov (dividend, Overflow);
3079
- EXPECT_TRUE (Overflow);
3080
- }
3081
3053
// int16 test overflow
3082
3054
{
3083
3055
using IntTy = int16_t ;
@@ -3110,24 +3082,30 @@ TEST(APIntTest, sfloordiv_ov) {
3110
3082
}
3111
3083
// test all of int8
3112
3084
{
3113
- bool Overflow = true ;
3085
+ bool Overflow = false ;
3114
3086
for (int i = -128 ; i < 128 ; ++i) {
3115
3087
for (int j = -128 ; j < 128 ; ++j) {
3116
- if (j == 0 || (i == - 128 && j == - 1 ) )
3088
+ if (j == 0 )
3117
3089
continue ;
3090
+
3118
3091
int8_t a = static_cast <int8_t >(i);
3119
3092
int8_t b = static_cast <int8_t >(j);
3120
3093
3121
3094
APInt divisor (8 , a, true );
3122
3095
APInt dividend (8 , b, true );
3096
+ APInt quotient = divisor.sfloordiv_ov (dividend, Overflow);
3097
+
3098
+ if (i == -128 && j == -1 ) {
3099
+ EXPECT_TRUE (Overflow);
3100
+ continue ;
3101
+ }
3102
+
3123
3103
if (((i >= 0 && j > 0 ) || (i <= 0 && j < 0 )) ||
3124
3104
(i % j == 0 )) // if quotient >= 0 and remain == 0 floordiv
3125
3105
// equivalent to div
3126
- EXPECT_EQ (divisor.sfloordiv_ov (dividend, Overflow).getSExtValue (),
3127
- a / b);
3106
+ EXPECT_EQ (quotient.getSExtValue (), a / b);
3128
3107
else
3129
- EXPECT_EQ (divisor.sfloordiv_ov (dividend, Overflow).getSExtValue (),
3130
- a / b - 1 );
3108
+ EXPECT_EQ (quotient.getSExtValue (), a / b - 1 );
3131
3109
EXPECT_FALSE (Overflow);
3132
3110
}
3133
3111
}
0 commit comments