@@ -952,41 +952,44 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
952
952
953
953
// Check if the denominator is uninitialized.
954
954
955
- if (RightV.isUninit ()) {
956
- NodeTy* DivUninit = Builder->generateNode (B, St, N2);
955
+ if (!RightV.isUnknown ()) {
956
+
957
+ if (RightV.isUninit ()) {
958
+ NodeTy* DivUninit = Builder->generateNode (B, St, N2);
959
+
960
+ if (DivUninit) {
961
+ DivUninit->markAsSink ();
962
+ BadDivides.insert (DivUninit);
963
+ }
964
+
965
+ continue ;
966
+ }
967
+
968
+ // Check for divide/remainder-by-zero.
969
+ //
970
+ // First, "assume" that the denominator is 0 or uninitialized.
971
+
972
+ bool isFeasible = false ;
973
+ StateTy ZeroSt = Assume (St, RightV, false , isFeasible);
957
974
958
- if (DivUninit) {
959
- DivUninit->markAsSink ();
960
- BadDivides.insert (DivUninit);
975
+ if (isFeasible) {
976
+ NodeTy* DivZeroNode = Builder->generateNode (B, ZeroSt, N2);
977
+
978
+ if (DivZeroNode) {
979
+ DivZeroNode->markAsSink ();
980
+ BadDivides.insert (DivZeroNode);
981
+ }
961
982
}
962
983
963
- continue ;
964
- }
984
+ // Second, "assume" that the denominator cannot be 0.
965
985
966
- // Check for divide/remainder-by-zero.
967
- //
968
- // First, "assume" that the denominator is 0 or uninitialized.
969
-
970
- bool isFeasible = false ;
971
- StateTy ZeroSt = Assume (St, RightV, false ,isFeasible);
972
-
973
- if (isFeasible) {
974
- NodeTy* DivZeroNode = Builder->generateNode (B, ZeroSt, N2);
986
+ isFeasible = false ;
987
+ St = Assume (St, RightV, true , isFeasible);
975
988
976
- if (DivZeroNode) {
977
- DivZeroNode->markAsSink ();
978
- BadDivides.insert (DivZeroNode);
979
- }
989
+ if (!isFeasible)
990
+ continue ;
980
991
}
981
992
982
- // Second, "assume" that the denominator cannot be 0.
983
-
984
- isFeasible = false ;
985
- St = Assume (St, RightV, true , isFeasible);
986
-
987
- if (!isFeasible)
988
- continue ;
989
-
990
993
// Fall-through. The logic below processes the divide.
991
994
}
992
995
@@ -1032,7 +1035,14 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
1032
1035
1033
1036
default : {
1034
1037
1035
- assert (B->isCompoundAssignmentOp ());
1038
+ assert (B->isCompoundAssignmentOp ());
1039
+
1040
+ if (Op >= BinaryOperator::AndAssign)
1041
+ ((int &) Op) -= (BinaryOperator::AndAssign - BinaryOperator::And);
1042
+ else
1043
+ ((int &) Op) -= BinaryOperator::MulAssign;
1044
+
1045
+ // Check if the LHS is uninitialized.
1036
1046
1037
1047
if (LeftV.isUninit ()) {
1038
1048
HandleUninitializedStore (B, N2);
@@ -1058,18 +1068,13 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
1058
1068
1059
1069
LVal LeftLV = cast<LVal>(LeftV);
1060
1070
1061
- // Propagate uninitialized values (right-side).
1062
-
1063
- if (RightV.isUninit ()) {
1064
- St = SetRVal (SetRVal (St, B, RightV), LeftLV, RightV);
1065
- break ;
1066
- }
1067
-
1068
1071
// Fetch the value of the LHS (the value of the variable, etc.).
1069
1072
1070
1073
RVal V = GetRVal (N1->getState (), LeftLV, B->getLHS ()->getType ());
1071
1074
1072
- // Propagate uninitialized value (left-side).
1075
+ // Propagate uninitialized value (left-side). We
1076
+ // propogate uninitialized values for the RHS below when
1077
+ // we also check for divide-by-zero.
1073
1078
1074
1079
if (V.isUninit ()) {
1075
1080
St = SetRVal (St, B, V);
@@ -1088,13 +1093,10 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
1088
1093
break ;
1089
1094
}
1090
1095
1091
- // Neither the LHS or the RHS have Unknown/Uninit values. Process
1092
- // the operation and store the result.
1093
-
1094
- if (Op >= BinaryOperator::AndAssign)
1095
- ((int &) Op) -= (BinaryOperator::AndAssign - BinaryOperator::And);
1096
- else
1097
- ((int &) Op) -= BinaryOperator::MulAssign;
1096
+ // At this point:
1097
+ //
1098
+ // The LHS is not Uninit/Unknown.
1099
+ // The RHS is not Unknown.
1098
1100
1099
1101
// Get the computation type.
1100
1102
QualType CTy = cast<CompoundAssignOperator>(B)->getComputationType ();
@@ -1120,7 +1122,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
1120
1122
1121
1123
continue ;
1122
1124
}
1123
-
1125
+
1124
1126
// First, "assume" that the denominator is 0.
1125
1127
1126
1128
bool isFeasible = false ;
@@ -1145,6 +1147,16 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
1145
1147
1146
1148
// Fall-through. The logic below processes the divide.
1147
1149
}
1150
+ else {
1151
+
1152
+ // Propagate uninitialized values (right-side).
1153
+
1154
+ if (RightV.isUninit ()) {
1155
+ St = SetRVal (SetRVal (St, B, RightV), LeftLV, RightV);
1156
+ break ;
1157
+ }
1158
+
1159
+ }
1148
1160
1149
1161
RVal Result = EvalCast (EvalBinOp (Op, V, RightV), B->getType ());
1150
1162
St = SetRVal (SetRVal (St, B, Result), LeftLV, Result);
0 commit comments