forked from OSchip/llvm-project
[SemaExpr] Factor out common diagnostic code for remainder/division.
llvm-svn: 243832
This commit is contained in:
parent
503a2594c3
commit
f76da1dac9
|
@ -7417,6 +7417,19 @@ static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS,
|
||||||
<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
|
<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS,
|
||||||
|
ExprResult &RHS,
|
||||||
|
SourceLocation Loc, bool IsDiv) {
|
||||||
|
// Check for division/remainder by zero.
|
||||||
|
unsigned Diag = (IsDiv) ? diag::warn_division_by_zero :
|
||||||
|
diag::warn_remainder_by_zero;
|
||||||
|
llvm::APSInt RHSValue;
|
||||||
|
if (!RHS.get()->isValueDependent() &&
|
||||||
|
RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0)
|
||||||
|
S.DiagRuntimeBehavior(Loc, RHS.get(),
|
||||||
|
S.PDiag(Diag) << RHS.get()->getSourceRange());
|
||||||
|
}
|
||||||
|
|
||||||
QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
|
QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
|
||||||
SourceLocation Loc,
|
SourceLocation Loc,
|
||||||
bool IsCompAssign, bool IsDiv) {
|
bool IsCompAssign, bool IsDiv) {
|
||||||
|
@ -7435,15 +7448,8 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
|
||||||
|
|
||||||
if (compType.isNull() || !compType->isArithmeticType())
|
if (compType.isNull() || !compType->isArithmeticType())
|
||||||
return InvalidOperands(Loc, LHS, RHS);
|
return InvalidOperands(Loc, LHS, RHS);
|
||||||
|
if (IsDiv)
|
||||||
// Check for division by zero.
|
DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
|
||||||
llvm::APSInt RHSValue;
|
|
||||||
if (IsDiv && !RHS.get()->isValueDependent() &&
|
|
||||||
RHS.get()->EvaluateAsInt(RHSValue, Context) && RHSValue == 0)
|
|
||||||
DiagRuntimeBehavior(Loc, RHS.get(),
|
|
||||||
PDiag(diag::warn_division_by_zero)
|
|
||||||
<< RHS.get()->getSourceRange());
|
|
||||||
|
|
||||||
return compType;
|
return compType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7467,15 +7473,7 @@ QualType Sema::CheckRemainderOperands(
|
||||||
|
|
||||||
if (compType.isNull() || !compType->isIntegerType())
|
if (compType.isNull() || !compType->isIntegerType())
|
||||||
return InvalidOperands(Loc, LHS, RHS);
|
return InvalidOperands(Loc, LHS, RHS);
|
||||||
|
DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, false /* IsDiv */);
|
||||||
// Check for remainder by zero.
|
|
||||||
llvm::APSInt RHSValue;
|
|
||||||
if (!RHS.get()->isValueDependent() &&
|
|
||||||
RHS.get()->EvaluateAsInt(RHSValue, Context) && RHSValue == 0)
|
|
||||||
DiagRuntimeBehavior(Loc, RHS.get(),
|
|
||||||
PDiag(diag::warn_remainder_by_zero)
|
|
||||||
<< RHS.get()->getSourceRange());
|
|
||||||
|
|
||||||
return compType;
|
return compType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue