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