Skip to content

Commit 0023e15

Browse files
committed
Optimize CheckInfNaNFunction function
1 parent 51dd53f commit 0023e15

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8476,24 +8476,25 @@ static bool IsInfinityFunction(const FunctionDecl *FDecl) {
84768476

84778477
void Sema::CheckInfNaNFunction(const CallExpr *Call,
84788478
const FunctionDecl *FDecl) {
8479+
if (!FDecl->getIdentifier()) {
8480+
return;
8481+
}
8482+
84798483
FPOptions FPO = Call->getFPFeaturesInEffect(getLangOpts());
8480-
bool HasIdentifier = FDecl->getIdentifier() != nullptr;
8481-
bool IsNaNOrIsUnordered =
8482-
IsStdFunction(FDecl, "isnan") || IsStdFunction(FDecl, "isunordered");
8483-
bool IsSpecialNaN =
8484-
HasIdentifier && IsInfOrNanFunction(FDecl->getName(), MathCheck::NaN);
8485-
if ((IsNaNOrIsUnordered || IsSpecialNaN) && FPO.getNoHonorNaNs()) {
8484+
if (FPO.getNoHonorNaNs() &&
8485+
(IsStdFunction(FDecl, "isnan") || IsStdFunction(FDecl, "isunordered") ||
8486+
IsInfOrNanFunction(FDecl->getName(), MathCheck::NaN))) {
84868487
Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
84878488
<< 1 << 0 << Call->getSourceRange();
8488-
} else {
8489-
bool IsInfOrIsFinite =
8490-
IsStdFunction(FDecl, "isinf") || IsStdFunction(FDecl, "isfinite");
8491-
bool IsInfinityOrIsSpecialInf =
8492-
HasIdentifier && (IsInfinityFunction(FDecl) ||
8493-
IsInfOrNanFunction(FDecl->getName(), MathCheck::Inf));
8494-
if ((IsInfOrIsFinite || IsInfinityOrIsSpecialInf) && FPO.getNoHonorInfs())
8495-
Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
8496-
<< 0 << 0 << Call->getSourceRange();
8489+
return;
8490+
}
8491+
8492+
if (FPO.getNoHonorInfs() &&
8493+
(IsStdFunction(FDecl, "isinf") || IsStdFunction(FDecl, "isfinite") ||
8494+
IsInfinityFunction(FDecl) ||
8495+
IsInfOrNanFunction(FDecl->getName(), MathCheck::Inf))) {
8496+
Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
8497+
<< 0 << 0 << Call->getSourceRange();
84978498
}
84988499
}
84998500

0 commit comments

Comments
 (0)