llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Zahira Ammarguellat (zahiraam)
Changes
Check for comparisons to INF and NaN when in ffast-math mode and generate a
warning.
---
Full diff: https://github.com/llvm/llvm-project/pull/76873.diff
5 Files Affected:
- (modified)
https://github.com/zahiraam ready_for_review
https://github.com/llvm/llvm-project/pull/76873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType
lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast
zahiraam wrote:
> Expanding the scope a bit, it would also be useful to have warnings for
> constant NaN or Inf values passed as arguments or used in binary operations.
Added that.
https://github.com/llvm/llvm-project/pull/76873
___
cfe-commits
@@ -13044,9 +13044,12 @@ static QualType checkArithmeticOrEnumeralCompare(Sema
, ExprResult ,
if (Type->isAnyComplexType() && BinaryOperator::isRelationalOp(Opc))
return S.InvalidOperands(Loc, LHS, RHS);
- // Check for comparisons of floating point operands using !=
@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType
lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast
@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType
lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast
@@ -2267,6 +2273,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl,
unsigned BuiltinID,
case Builtin::BI__builtin_signbit:
case Builtin::BI__builtin_signbitf:
case Builtin::BI__builtin_signbitl:
+FPO = TheCall->getFPFeaturesInEffect(getLangOpts());
https://github.com/zahiraam updated
https://github.com/llvm/llvm-project/pull/76873
>From 7dbaf037b6b2196cee7c0c837e0a89ce3c2556ed Mon Sep 17 00:00:00 2001
From: Ammarguellat
Date: Wed, 3 Jan 2024 14:37:17 -0800
Subject: [PATCH 1/2] [CLANG] Add warning when comparing to INF or NAN in fast
@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType
lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast
@@ -13044,9 +13044,12 @@ static QualType checkArithmeticOrEnumeralCompare(Sema
, ExprResult ,
if (Type->isAnyComplexType() && BinaryOperator::isRelationalOp(Opc))
return S.InvalidOperands(Loc, LHS, RHS);
- // Check for comparisons of floating point operands using !=
@@ -2267,6 +2273,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl,
unsigned BuiltinID,
case Builtin::BI__builtin_signbit:
case Builtin::BI__builtin_signbitf:
case Builtin::BI__builtin_signbitl:
+FPO = TheCall->getFPFeaturesInEffect(getLangOpts());
@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType
lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast
@@ -2245,6 +2246,11 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl,
unsigned BuiltinID,
case Builtin::BI__builtin_islessequal:
case Builtin::BI__builtin_islessgreater:
case Builtin::BI__builtin_isunordered:
+if (BuiltinID == Builtin::BI__builtin_isunordered)
@@ -6771,6 +6771,9 @@ def warn_pointer_sub_null_ptr : Warning<
def warn_floatingpoint_eq : Warning<
"comparing floating point with == or != is unsafe">,
InGroup>, DefaultIgnore;
+def warn_fast_floatingpoint_eq : Warning<
+ "explicit comparison with %0 in fast floating
https://github.com/andykaylor commented:
Expanding the scope a bit, it would also be useful to have warnings for
constant NaN or Inf values passed as arguments or used in binary operations.
https://github.com/llvm/llvm-project/pull/76873
___
https://github.com/andykaylor edited
https://github.com/llvm/llvm-project/pull/76873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/zahiraam edited
https://github.com/llvm/llvm-project/pull/76873
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/zahiraam created
https://github.com/llvm/llvm-project/pull/76873
None
>From 7dbaf037b6b2196cee7c0c837e0a89ce3c2556ed Mon Sep 17 00:00:00 2001
From: Ammarguellat
Date: Wed, 3 Jan 2024 14:37:17 -0800
Subject: [PATCH] [CLANG] Add warning when comparing to INF or NAN in fast
19 matches
Mail list logo