[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-29 Thread via cfe-commits

mikaelholmen wrote:

> > > Is this expected and wanted?
> > 
> > 
> > Good catch! I would not expect that diagnostic; we should silence the 
> > diagnostic if it's used in a `#ifdef`, `#elifdef`, or `defined` because the 
> > value isn't necessary. Perhaps we should also silence something like 
> > `sizeof(INFINITY)` because it's unevaluated?
> 
> Thanks @mikaelholmen and @AaronBallman. I will take a look and create a PR to 
> fix the issue.

Hi @zahiraam !
Did you get anywhere with this?

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


[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-24 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> > Is this expected and wanted?
> 
> Good catch! I would not expect that diagnostic; we should silence the 
> diagnostic if it's used in a `#ifdef`, `#elifdef`, or `defined` because the 
> value isn't necessary. Perhaps we should also silence something like 
> `sizeof(INFINITY)` because it's unevaluated?

Thanks @mikaelholmen and @AaronBallman. I will take a look and create a PR to 
fix the issue.

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


[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-19 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,181 @@
+// Use of NAN macro will trigger a warning "infinity defined in macro" because
+// on Windows the NAN macro is defined using INFINITY. See below.
+
+// RUN: %clang_cc1 -x c++ -verify=no-inf-no-nan -triple 
powerpc64le-unknown-unknown %s \
+// RUN: -menable-no-infs -menable-no-nans
+
+// RUN: %clang_cc1 -x c++ -verify -triple powerpc64le-unknown-unknown %s \
+// RUN: -DNOFAST=1
+
+// RUN: %clang_cc1 -x c++ -verify=no-inf -triple powerpc64le-unknown-unknown 
%s \
+// RUN: -menable-no-infs
+
+// RUN: %clang_cc1 -x c++ -verify=no-nan -triple powerpc64le-unknown-unknown 
%s \
+// RUN: -menable-no-nans
+
+int isunorderedf (float x, float y);
+#if NOFAST
+// expected-no-diagnostics

AaronBallman wrote:

Same thing here as with the other test.

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


[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-19 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

The changes LGTM aside from some minor improvements to the tests.

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


[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-18 Thread Aaron Ballman via cfe-commits


@@ -2835,6 +2835,9 @@ class Preprocessor {
 if (Identifier.getIdentifierInfo()->isRestrictExpansion() &&
 !SourceMgr.isInMainFile(Identifier.getLocation()))
   emitRestrictExpansionWarning(Identifier);
+
+if (Identifier.getIdentifierInfo()->getName() == "INFINITY")

AaronBallman wrote:

Because there are other C standard libraries which do something different. For 
example, musl: https://git.musl-libc.org/cgit/musl/tree/include/math.h#n18

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


[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

2024-01-15 Thread Zahira Ammarguellat via cfe-commits


@@ -13861,6 +13897,36 @@ 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 modes: float evaluation will not result in inf or nan.
+void Sema::CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,

zahiraam wrote:

I have actually tried that but I noticed that 
`getSpellingOfSingleCharacterNumericConstant` of inf/nan will both return "0" 
so I will have no way to distinguish between inf + 1 and 0 + 1 and both will 
generate a warning. Unless there is other way of finding out that the token is 
nan/inf?


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