Skip to content
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

flang-new 19.0: "warning: overflow on power with INTEGER exponent“ #88151

Closed
zaikunzhang opened this issue Apr 9, 2024 · 4 comments · Fixed by #88188
Closed

flang-new 19.0: "warning: overflow on power with INTEGER exponent“ #88151

zaikunzhang opened this issue Apr 9, 2024 · 4 comments · Fixed by #88188
Assignees

Comments

@zaikunzhang
Copy link

zaikunzhang commented Apr 9, 2024

Hi,

I am using flang-new 19.0. With the following Fortran code

! test_overflow.f90
program test_overflow
implicit none
print *, range(0.0)
print *, 10.0**(-32.0)
print *, 10.0**(-32)
end program test_overflow                                                                                                    

I got the following:

$ uname -a && flang-new --version && flang-new test_overflow.f90 && ./a.out 
Linux 6.5.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 10:22:43 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
flang-new version 19.0.0git (git@github.com:llvm/llvm-project.git 37c175af955f0aeab67e8c553a0a47b2ed0fdba2)
Target: x86_64-unknown-linux-gnu
Thread model: posix
./test_overflow.f90:6:10: warning: overflow on power with INTEGER exponent
  print *, 10.0**(-32)
           ^^^^^^^^^^^
 37
 1.E-32
 9.9999995E-33

Note that print *, 10.0**(-32) leads to an "overflow on power with INTEGER exponent".

What is overflowing? Is this expected or a false positive?

Thanks.

@llvmbot
Copy link
Member

llvmbot commented Apr 9, 2024

@llvm/issue-subscribers-flang-frontend

Author: Zaikun ZHANG (zaikunzhang)

Hi,

I am using flang-new 19.0. With the following Fortran code

! test_overflow.f90
program test_overflow
implicit none
print *, range(0.0)
print *, 10.0**(-32.0)
print *, 10.0**(-32)
end program test_overflow                                                                                                    

I got the following:

$ uname -a && flang-new --version && flang-new test_overflow.f90 && ./a.out 
Linux 6.5.0-26-generic #<!-- -->26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 10:22:43 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
flang-new version 19.0.0git (git@<!-- -->github.com:llvm/llvm-project.git 37c175af955f0aeab67e8c553a0a47b2ed0fdba2)
Target: x86_64-unknown-linux-gnu
Thread model: posix
./test_overflow.f90:6:10: warning: overflow on power with INTEGER exponent
  print *, 10.0**(-32)
           ^^^^^^^^^^^
 37
 1.E-32
 9.9999995E-33

Note that print *, 10.0**(-32) leads to an "overflow on power with INTEGER exponent".

What is overflowing? Is this expected or a false positive?

Thanks.

@klausler
Copy link
Contributor

klausler commented Apr 9, 2024

It's a bogus warning and you can ignore it. Will fix.

@klausler klausler self-assigned this Apr 9, 2024
klausler added a commit to klausler/llvm-project that referenced this issue Apr 9, 2024
…er powers

The code that folds exponentiation by an integer power can report
a spurious overflow warning because it calculates one last unnecessary
square of the base value.  10.**(+/-32) exposes the problem --
the value of 10.**64 is calculated but not needed.  Rearrange the
implementation to only calculate squares that are necessary.

Fixes llvm#88151.
@klausler
Copy link
Contributor

klausler commented Apr 9, 2024

Fixed by #88188.

@zaikunzhang
Copy link
Author

@klausler Great! Thank you for the very prompt fix.

Indeed, I spotted this bug by trying

10.0_WP**(-range(0.0_WP))

with WP being single. I hope your fix removes the warning in this case and applies to other WP as well.

klausler added a commit that referenced this issue Apr 22, 2024
#88188)

…er powers

The code that folds exponentiation by an integer power can report a
spurious overflow warning because it calculates one last unnecessary
square of the base value. 10.**(+/-32) exposes the problem -- the value
of 10.**64 is calculated but not needed. Rearrange the implementation to
only calculate squares that are necessary.

Fixes #88151.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants