@@ -563,9 +563,9 @@ static bool interp_floating_comparison(InterpState &S, CodePtr OpPC,
563
563
case Builtin::BI__builtin_islessequal:
564
564
return LHS <= RHS;
565
565
case Builtin::BI__builtin_islessgreater: {
566
- ComparisonCategoryResult cmp = LHS.compare (RHS);
567
- return cmp == ComparisonCategoryResult::Less ||
568
- cmp == ComparisonCategoryResult::Greater;
566
+ ComparisonCategoryResult Cmp = LHS.compare (RHS);
567
+ return Cmp == ComparisonCategoryResult::Less ||
568
+ Cmp == ComparisonCategoryResult::Greater;
569
569
}
570
570
case Builtin::BI__builtin_isunordered:
571
571
return LHS.compare (RHS) == ComparisonCategoryResult::Unordered;
@@ -583,8 +583,7 @@ static bool interp_floating_comparison(InterpState &S, CodePtr OpPC,
583
583
static bool interp__builtin_isfpclass (InterpState &S, CodePtr OpPC,
584
584
const InterpFrame *Frame,
585
585
const CallExpr *Call) {
586
- PrimType FPClassArgT = *S.getContext ().classify (Call->getArg (1 )->getType ());
587
- APSInt FPClassArg = popToAPSInt (S.Stk , FPClassArgT);
586
+ APSInt FPClassArg = popToAPSInt (S, Call->getArg (1 ));
588
587
const Floating &F = S.Stk .pop <Floating>();
589
588
590
589
int32_t Result = static_cast <int32_t >(
@@ -655,8 +654,7 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr OpPC,
655
654
static bool interp__builtin_abs (InterpState &S, CodePtr OpPC,
656
655
const InterpFrame *Frame,
657
656
const CallExpr *Call) {
658
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
659
- APSInt Val = popToAPSInt (S.Stk , ArgT);
657
+ APSInt Val = popToAPSInt (S, Call->getArg (0 ));
660
658
if (Val ==
661
659
APSInt (APInt::getSignedMinValue (Val.getBitWidth ()), /* IsUnsigned=*/ false ))
662
660
return false ;
@@ -674,8 +672,7 @@ static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
674
672
const Pointer &Arg = S.Stk .pop <Pointer>();
675
673
Val = convertBoolVectorToInt (Arg);
676
674
} else {
677
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
678
- Val = popToAPSInt (S.Stk , ArgT);
675
+ Val = popToAPSInt (S, Call->getArg (0 ));
679
676
}
680
677
pushInteger (S, Val.popcount (), Call->getType ());
681
678
return true ;
@@ -684,26 +681,23 @@ static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
684
681
static bool interp__builtin_parity (InterpState &S, CodePtr OpPC,
685
682
const InterpFrame *Frame,
686
683
const CallExpr *Call) {
687
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
688
- APSInt Val = popToAPSInt (S.Stk , ArgT);
684
+ APSInt Val = popToAPSInt (S, Call->getArg (0 ));
689
685
pushInteger (S, Val.popcount () % 2 , Call->getType ());
690
686
return true ;
691
687
}
692
688
693
689
static bool interp__builtin_clrsb (InterpState &S, CodePtr OpPC,
694
690
const InterpFrame *Frame,
695
691
const CallExpr *Call) {
696
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
697
- APSInt Val = popToAPSInt (S.Stk , ArgT);
692
+ APSInt Val = popToAPSInt (S, Call->getArg (0 ));
698
693
pushInteger (S, Val.getBitWidth () - Val.getSignificantBits (), Call->getType ());
699
694
return true ;
700
695
}
701
696
702
697
static bool interp__builtin_bitreverse (InterpState &S, CodePtr OpPC,
703
698
const InterpFrame *Frame,
704
699
const CallExpr *Call) {
705
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
706
- APSInt Val = popToAPSInt (S.Stk , ArgT);
700
+ APSInt Val = popToAPSInt (S, Call->getArg (0 ));
707
701
pushInteger (S, Val.reverseBits (), Call->getType ());
708
702
return true ;
709
703
}
@@ -746,11 +740,8 @@ static bool interp__builtin_expect(InterpState &S, CodePtr OpPC,
746
740
static bool interp__builtin_rotate (InterpState &S, CodePtr OpPC,
747
741
const InterpFrame *Frame,
748
742
const CallExpr *Call, bool Right) {
749
- PrimType AmountT = *S.getContext ().classify (Call->getArg (1 )->getType ());
750
- PrimType ValueT = *S.getContext ().classify (Call->getArg (0 )->getType ());
751
-
752
- APSInt Amount = popToAPSInt (S.Stk , AmountT);
753
- APSInt Value = popToAPSInt (S.Stk , ValueT);
743
+ APSInt Amount = popToAPSInt (S, Call->getArg (1 ));
744
+ APSInt Value = popToAPSInt (S, Call->getArg (0 ));
754
745
755
746
APSInt Result;
756
747
if (Right)
@@ -767,8 +758,7 @@ static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
767
758
static bool interp__builtin_ffs (InterpState &S, CodePtr OpPC,
768
759
const InterpFrame *Frame,
769
760
const CallExpr *Call) {
770
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
771
- APSInt Value = popToAPSInt (S.Stk , ArgT);
761
+ APSInt Value = popToAPSInt (S, Call->getArg (0 ));
772
762
773
763
uint64_t N = Value.countr_zero ();
774
764
pushInteger (S, N == Value.getBitWidth () ? 0 : N + 1 , Call->getType ());
@@ -796,8 +786,7 @@ static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
796
786
static bool interp__builtin_eh_return_data_regno (InterpState &S, CodePtr OpPC,
797
787
const InterpFrame *Frame,
798
788
const CallExpr *Call) {
799
- PrimType ArgT = *S.getContext ().classify (Call->getArg (0 )->getType ());
800
- APSInt Arg = popToAPSInt (S.Stk , ArgT);
789
+ APSInt Arg = popToAPSInt (S, Call->getArg (0 ));
801
790
802
791
int Result = S.getASTContext ().getTargetInfo ().getEHDataRegisterNumber (
803
792
Arg.getZExtValue ());
@@ -971,17 +960,15 @@ static bool interp__builtin_clz(InterpState &S, CodePtr OpPC,
971
960
unsigned BuiltinOp) {
972
961
973
962
std::optional<APSInt> Fallback;
974
- if (BuiltinOp == Builtin::BI__builtin_clzg && Call->getNumArgs () == 2 ) {
975
- PrimType FallbackT = *S.getContext ().classify (Call->getArg (1 ));
976
- Fallback = popToAPSInt (S.Stk , FallbackT);
977
- }
963
+ if (BuiltinOp == Builtin::BI__builtin_clzg && Call->getNumArgs () == 2 )
964
+ Fallback = popToAPSInt (S, Call->getArg (1 ));
965
+
978
966
APSInt Val;
979
967
if (Call->getArg (0 )->getType ()->isExtVectorBoolType ()) {
980
968
const Pointer &Arg = S.Stk .pop <Pointer>();
981
969
Val = convertBoolVectorToInt (Arg);
982
970
} else {
983
- PrimType ValT = *S.getContext ().classify (Call->getArg (0 ));
984
- Val = popToAPSInt (S.Stk , ValT);
971
+ Val = popToAPSInt (S, Call->getArg (0 ));
985
972
}
986
973
987
974
// When the argument is 0, the result of GCC builtins is undefined, whereas
@@ -1008,17 +995,15 @@ static bool interp__builtin_ctz(InterpState &S, CodePtr OpPC,
1008
995
const InterpFrame *Frame, const CallExpr *Call,
1009
996
unsigned BuiltinID) {
1010
997
std::optional<APSInt> Fallback;
1011
- if (BuiltinID == Builtin::BI__builtin_ctzg && Call->getNumArgs () == 2 ) {
1012
- PrimType FallbackT = *S.getContext ().classify (Call->getArg (1 ));
1013
- Fallback = popToAPSInt (S.Stk , FallbackT);
1014
- }
998
+ if (BuiltinID == Builtin::BI__builtin_ctzg && Call->getNumArgs () == 2 )
999
+ Fallback = popToAPSInt (S, Call->getArg (1 ));
1000
+
1015
1001
APSInt Val;
1016
1002
if (Call->getArg (0 )->getType ()->isExtVectorBoolType ()) {
1017
1003
const Pointer &Arg = S.Stk .pop <Pointer>();
1018
1004
Val = convertBoolVectorToInt (Arg);
1019
1005
} else {
1020
- PrimType ValT = *S.getContext ().classify (Call->getArg (0 ));
1021
- Val = popToAPSInt (S.Stk , ValT);
1006
+ Val = popToAPSInt (S, Call->getArg (0 ));
1022
1007
}
1023
1008
1024
1009
if (Val == 0 ) {
@@ -1036,13 +1021,10 @@ static bool interp__builtin_ctz(InterpState &S, CodePtr OpPC,
1036
1021
static bool interp__builtin_bswap (InterpState &S, CodePtr OpPC,
1037
1022
const InterpFrame *Frame,
1038
1023
const CallExpr *Call) {
1039
- PrimType ReturnT = *S.getContext ().classify (Call->getType ());
1040
- PrimType ValT = *S.getContext ().classify (Call->getArg (0 ));
1041
- const APSInt &Val = popToAPSInt (S.Stk , ValT);
1024
+ const APSInt &Val = popToAPSInt (S, Call->getArg (0 ));
1042
1025
assert (Val.getActiveBits () <= 64 );
1043
1026
1044
- INT_TYPE_SWITCH (ReturnT,
1045
- { S.Stk .push <T>(T::from (Val.byteSwap ().getZExtValue ())); });
1027
+ pushInteger (S, Val.byteSwap (), Call->getType ());
1046
1028
return true ;
1047
1029
}
1048
1030
@@ -1057,9 +1039,8 @@ static bool interp__builtin_atomic_lock_free(InterpState &S, CodePtr OpPC,
1057
1039
return true ;
1058
1040
};
1059
1041
1060
- PrimType ValT = *S.getContext ().classify (Call->getArg (0 ));
1061
1042
const Pointer &Ptr = S.Stk .pop <Pointer>();
1062
- const APSInt &SizeVal = popToAPSInt (S. Stk , ValT );
1043
+ const APSInt &SizeVal = popToAPSInt (S, Call-> getArg ( 0 ) );
1063
1044
1064
1045
// For __atomic_is_lock_free(sizeof(_Atomic(T))), if the size is a power
1065
1046
// of two less than or equal to the maximum inline atomic width, we know it
@@ -1125,21 +1106,17 @@ static bool interp__builtin_c11_atomic_is_lock_free(InterpState &S,
1125
1106
CodePtr OpPC,
1126
1107
const InterpFrame *Frame,
1127
1108
const CallExpr *Call) {
1128
- PrimType ValT = *S.getContext ().classify (Call->getArg (0 ));
1129
- const APSInt &SizeVal = popToAPSInt (S.Stk , ValT);
1130
-
1131
- auto returnBool = [&S](bool Value) -> bool {
1132
- S.Stk .push <Boolean>(Value);
1133
- return true ;
1134
- };
1109
+ const APSInt &SizeVal = popToAPSInt (S, Call->getArg (0 ));
1135
1110
1136
1111
CharUnits Size = CharUnits::fromQuantity (SizeVal.getZExtValue ());
1137
1112
if (Size.isPowerOfTwo ()) {
1138
1113
// Check against inlining width.
1139
1114
unsigned InlineWidthBits =
1140
1115
S.getASTContext ().getTargetInfo ().getMaxAtomicInlineWidth ();
1141
- if (Size <= S.getASTContext ().toCharUnitsFromBits (InlineWidthBits))
1142
- return returnBool (true );
1116
+ if (Size <= S.getASTContext ().toCharUnitsFromBits (InlineWidthBits)) {
1117
+ S.Stk .push <Boolean>(true );
1118
+ return true ;
1119
+ }
1143
1120
}
1144
1121
1145
1122
return false ; // returnBool(false);
@@ -1324,10 +1301,8 @@ static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
1324
1301
!Call->getArg (1 )->getType ()->isIntegerType ())
1325
1302
return false ;
1326
1303
1327
- PrimType ValT = *S.Ctx .classify (Call->getArg (0 ));
1328
- PrimType IndexT = *S.Ctx .classify (Call->getArg (1 ));
1329
- APSInt Index = popToAPSInt (S.Stk , IndexT);
1330
- APSInt Val = popToAPSInt (S.Stk , ValT);
1304
+ APSInt Index = popToAPSInt (S, Call->getArg (1 ));
1305
+ APSInt Val = popToAPSInt (S, Call->getArg (0 ));
1331
1306
1332
1307
unsigned BitWidth = Val.getBitWidth ();
1333
1308
uint64_t Shift = Index.extractBitsAsZExtValue (8 , 0 );
0 commit comments