@@ -1097,6 +1097,27 @@ void ScalarExprEmitter::EmitIntegerTruncationCheck(Value *Src, QualType SrcType,
1097
1097
{Src, Dst});
1098
1098
}
1099
1099
1100
+ static llvm::Value *EmitIsNegativeTestHelper (Value *V, QualType VType,
1101
+ const char *Name,
1102
+ CGBuilderTy &Builder) {
1103
+ // NOTE: zero value is considered to be non-negative.
1104
+ // Is this value a signed type?
1105
+ bool VSigned = VType->isSignedIntegerOrEnumerationType ();
1106
+ llvm::Type *VTy = V->getType ();
1107
+ if (!VSigned) {
1108
+ // If the value is unsigned, then it is never negative.
1109
+ // FIXME: can we encounter non-scalar VTy here?
1110
+ return llvm::ConstantInt::getFalse (VTy->getContext ());
1111
+ }
1112
+ // Get the zero of the same type with which we will be comparing.
1113
+ llvm::Constant *Zero = llvm::ConstantInt::get (VTy, 0 );
1114
+ // %V.isnegative = icmp slt %V, 0
1115
+ // I.e is %V *strictly* less than zero, does it have negative value?
1116
+ return Builder.CreateICmp (llvm::ICmpInst::ICMP_SLT, V, Zero,
1117
+ llvm::Twine (Name) + " ." + V->getName () +
1118
+ " .negativitycheck" );
1119
+ };
1120
+
1100
1121
// Should be called within CodeGenFunction::SanitizerScope RAII scope.
1101
1122
// Returns 'i1 false' when the conversion Src -> Dst changed the sign.
1102
1123
static std::pair<ScalarExprEmitter::ImplicitConversionCheckKind,
@@ -1121,30 +1142,12 @@ EmitIntegerSignChangeCheckHelper(Value *Src, QualType SrcType, Value *Dst,
1121
1142
assert (((SrcBits != DstBits) || (SrcSigned != DstSigned)) &&
1122
1143
" either the widths should be different, or the signednesses." );
1123
1144
1124
- // NOTE: zero value is considered to be non-negative.
1125
- auto EmitIsNegativeTest = [&Builder](Value *V, QualType VType,
1126
- const char *Name) -> Value * {
1127
- // Is this value a signed type?
1128
- bool VSigned = VType->isSignedIntegerOrEnumerationType ();
1129
- llvm::Type *VTy = V->getType ();
1130
- if (!VSigned) {
1131
- // If the value is unsigned, then it is never negative.
1132
- // FIXME: can we encounter non-scalar VTy here?
1133
- return llvm::ConstantInt::getFalse (VTy->getContext ());
1134
- }
1135
- // Get the zero of the same type with which we will be comparing.
1136
- llvm::Constant *Zero = llvm::ConstantInt::get (VTy, 0 );
1137
- // %V.isnegative = icmp slt %V, 0
1138
- // I.e is %V *strictly* less than zero, does it have negative value?
1139
- return Builder.CreateICmp (llvm::ICmpInst::ICMP_SLT, V, Zero,
1140
- llvm::Twine (Name) + " ." + V->getName () +
1141
- " .negativitycheck" );
1142
- };
1143
-
1144
1145
// 1. Was the old Value negative?
1145
- llvm::Value *SrcIsNegative = EmitIsNegativeTest (Src, SrcType, " src" );
1146
+ llvm::Value *SrcIsNegative =
1147
+ EmitIsNegativeTestHelper (Src, SrcType, " src" , Builder);
1146
1148
// 2. Is the new Value negative?
1147
- llvm::Value *DstIsNegative = EmitIsNegativeTest (Dst, DstType, " dst" );
1149
+ llvm::Value *DstIsNegative =
1150
+ EmitIsNegativeTestHelper (Dst, DstType, " dst" , Builder);
1148
1151
// 3. Now, was the 'negativity status' preserved during the conversion?
1149
1152
// NOTE: conversion from negative to zero is considered to change the sign.
1150
1153
// (We want to get 'false' when the conversion changed the sign)
0 commit comments