-
Notifications
You must be signed in to change notification settings - Fork 13.5k
isless macro throws FE_INVALID when NAN is specified to the argument #59924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The program as written invokes undefined behavior, so there is no bug. You must use "#pragma STDC FENV_ACCESS ON" to avoid that. See discussion in #8472. |
@rotateright Thanks for your answer. I understood that this is not a bug for now.
When |
@rotateright I tried newer version of the compiler as follows, and the warning
|
Yes, it seems like a bug if the compiler supports FENV_ACCESS for your target now, but it shows an exception. |
@rotateright Thanks for replying.
If the type is "double", In AArch64, if the type is "double", instructions that raise the floating point exception is not generated since the software floating point library is not used e.g. https://godbolt.org/z/14Tqhfr87. But, In AArch64, if the type is "long double", So, I think that there need to be the instructions checking that both of the arguments passed to |
Thanks for the analysis @utsumi-fj ! You can show LLVM IR on godbolt by adding "-emit-llvm" to the compiler flags. I'll paste the example here for easier access: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
@.str = private unnamed_addr constant [5 x i8] c"test\00", align 1
@.str.1 = private unnamed_addr constant [11 x i8] c"FE_INVALID\00", align 1
define dso_local i32 @main() #0 {
%1 = alloca i32, align 4
%2 = alloca fp128, align 16
store i32 0, ptr %1, align 4
%3 = call fp128 @llvm.experimental.constrained.fpext.f128.f32(float 0x7FF8000000000000, metadata !"fpexcept.strict") #4
store fp128 %3, ptr %2, align 16
%4 = load fp128, ptr %2, align 16
%5 = call fp128 @llvm.experimental.constrained.fpext.f128.f64(double 1.000000e+00, metadata !"fpexcept.strict") #4
%6 = call i1 @llvm.experimental.constrained.fcmp.f128(fp128 %4, fp128 %5, metadata !"olt", metadata !"fpexcept.strict") #4
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(ptr noundef @.str) #4
br label %9
9: ; preds = %7, %0
%10 = call i32 @fetestexcept(i32 noundef 1) #5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(ptr noundef @.str.1) #4
br label %14
14: ; preds = %12, %9
ret i32 0
}
declare fp128 @llvm.experimental.constrained.fpext.f128.f32(float, metadata) #1
declare fp128 @llvm.experimental.constrained.fpext.f128.f64(double, metadata) #1
declare i1 @llvm.experimental.constrained.fcmp.f128(fp128, fp128, metadata, metadata) #1
declare i32 @puts(ptr noundef) #2
declare i32 @fetestexcept(i32 noundef) #3
attributes #0 = { noinline nounwind optnone strictfp uwtable "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "strictfp" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+outline-atomics,+v8a,-fmv" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
attributes #2 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+outline-atomics,+v8a,-fmv" }
attributes #3 = { nounwind "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+outline-atomics,+v8a,-fmv" }
attributes #4 = { strictfp }
attributes #5 = { nounwind strictfp }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
!llvm.ident = !{!6}
!0 = !{i32 7, !"Dwarf Version", i32 4}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 8, !"PIC Level", i32 2}
!3 = !{i32 7, !"PIE Level", i32 2}
!4 = !{i32 7, !"uwtable", i32 2}
!5 = !{i32 7, !"frame-pointer", i32 1}
!6 = !{!"clang version 16.0.0 (https://github.com/llvm/llvm-project.git 8efb8f776abf1cb66107c42b47e6a127828c4db0)"} |
@llvm/issue-subscribers-backend-aarch64 |
This looks like it could be a bug in the implementation of __lttf2 that you're using. https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html doesn't say anything explicit about floating-point exceptions, but neither the libgcc nor compiler-rt implementations will raise an exception when an input is NaN. |
@john-brawn-arm Thanks for your comment.
Also, I tried compiler-rt. When using compiler-rt, this issue was not detected i.e. a floating point exception was not raised. According to the document https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html, the semantics of
The above is not saying about when either of the arguments is NaN. And the following sentence is also written in this document.
So, I think that NAN should not be passed to |
Probably this is an issue mentioned in D71897 and is marked as |
@kawashima-fj Thanks for your comment. I didn't know the discussion in D71897. I agree with you. |
Everyone, I also encountered a similar problem on the riscv64 platform, and the reason may be the same as this problem. Code:
Error message: Clang version: |
There's a PR to add a special case to NumPy on aarch64 for clang to work around this: numpy/numpy#28232 |
Uh oh!
There was an error while loading. Please reload this page.
The
isless
macro throwsFE_INVALID
when NAN is specified to the argument.When one of the arguments of
isless
is unordered,isless
should not throw "invalid" floating-point exception.Reproducer:
test.c
Compilation commands and execution result:
This issue was detected in AArch64 machine.
The text was updated successfully, but these errors were encountered: