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

BLD: Add clang -ftrapping-math also for compiler_so #19479

Merged
merged 3 commits into from Jul 18, 2021

Conversation

seberg
Copy link
Member

@seberg seberg commented Jul 14, 2021

Apparently, there is a second compiler_so that is actually the
main compiler being used, and modifying only the first one is just
futile.

Closes gh-19427 in theory. In practice, I somewhat expect that clang only decided that warning flags are worth any consideration so recently, that this will just break old clang versions


I have tested that this works: gh-19476 passes with this. What is the minimum clang version we actually support? I expect this needs at least version 10 (which is fairly new), but I can't compile locally on version 9. (I guess the CI run will tell me that this won't actually work :/)

@github-actions github-actions bot added the 36 - Build Build related PR label Jul 14, 2021
@seberg
Copy link
Member Author

seberg commented Jul 14, 2021

I somewhat expected this would fail, but I don't understand it. The mac CI build uses Clang 11.0.0, my local build uses Debian clang version 11.0.1-2, which doesn't really sound like 11.0.0 should reject a flag that my version is happy to accept.

@seberg seberg changed the title BLD: Add clang -ffp-exception-behavior=strict also for _so BLD: Add clang -ftrapping-math also for _so Jul 15, 2021
Apparently, there is a second `compiler_so` that is actually the
main compiler being used, and modifying only the first one is just
futile.

The old try was `-ffp-exception-behavior=strict`, but that seems to
be a fairly new addition (and doesn't even work on MacOS with 10.0)

`-ftrapping-math` seems to be the older, equivalent option.
@seberg
Copy link
Member Author

seberg commented Jul 15, 2021

I also confirmed that it does indeed fix gh-18005 for my clang version, so changing that comment.

I expect the -ftrapping-math will now work correctly (and the docs mention that flag at least for clang 5.0 – that is the furthest back I checked)

EDIT: But, this probably needs a release note. And I am not sure what to do about the 1.21 release notes being incorrect...

@seberg seberg added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jul 15, 2021
@seberg seberg closed this Jul 15, 2021
@seberg seberg reopened this Jul 15, 2021
@seberg
Copy link
Member Author

seberg commented Jul 15, 2021

So for those checking this: https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffp-exception-behavior explains that -ffp-excetion-behaviour=strict should be good for us while: https://clang.llvm.org/docs/UsersManual.html#cmdoption-fdenormal-fp-math (go slightly lower, the anchor is missing), says:

Control floating point exception behavior. -fno-trapping-math allows optimizations that assume that floating point operations cannot generate traps such as divide-by-zero, overflow and underflow.

and

The option -ftrapping-math behaves identically to -ffp-exception-behavior=strict.


I think the main question is basically the old question: Is modifying self.compiler and self.compiler_so reasonable? The self.compiler_so does work and gets used.

@seberg seberg removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jul 15, 2021
@seberg seberg changed the title BLD: Add clang -ftrapping-math also for _so BLD: Add clang -ftrapping-math also for compiler_so Jul 15, 2021
@mattip
Copy link
Member

mattip commented Jul 18, 2021

I think we should put this PR in. @charris, thoughts?

Is modifying self.compiler and self.compiler_so reasonable? The self.compiler_so does work and gets used.

Well, this PR does not add a new modification, it fixes the current one.

@charris
Copy link
Member

charris commented Jul 18, 2021

I don't have a problem putting this in. What is the question about 1.21.x release notes?

@seberg
Copy link
Member Author

seberg commented Jul 18, 2021

@charris my question was whether we should do something about them being incorrect?

@charris
Copy link
Member

charris commented Jul 18, 2021

my question was whether we should do something about them being incorrect?

I tend to regard release notes as history, flaws and all, after the release. We could backport this change if you wish and mention that in a later release note.

@seberg
Copy link
Member Author

seberg commented Jul 18, 2021

OK, sounds good. I am hesitant about backporting, since I have no idea if this may have side-effects for some.

@mattip mattip merged commit 6388471 into numpy:main Jul 18, 2021
@mattip
Copy link
Member

mattip commented Jul 18, 2021

Thanks @seberg

@seberg seberg deleted the fixup-clang-flag-try branch July 18, 2021 20:27
@seberg

This comment was marked as outdated.

rgommers added a commit to rgommers/numpy that referenced this pull request Jun 27, 2023
The distutils build also uses this flag, and it avoids some problems
with `floor_divide` and similar functions (xref numpygh-19479).
rgommers added a commit to rgommers/numpy that referenced this pull request Jun 27, 2023
The distutils build also uses this flag, and it avoids some problems
with `floor_divide` and similar functions (xref numpygh-19479).

For older macOS arm64 Clang versions, the flag does get accepted, but then
gets overridden because it's not actually supported - which yields these
warnings:
```
warning: overriding currently unsupported use of floating point exceptions on this target [-Wunsupported-floating-point-opt]
```
Since they're a little annoying to suppress and will go away when updating to
the latest XCode version, we'll ignore these warnings.
charris pushed a commit to charris/numpy that referenced this pull request Jul 14, 2023
The distutils build also uses this flag, and it avoids some problems
with `floor_divide` and similar functions (xref numpygh-19479).

For older macOS arm64 Clang versions, the flag does get accepted, but then
gets overridden because it's not actually supported - which yields these
warnings:
```
warning: overriding currently unsupported use of floating point exceptions on this target [-Wunsupported-floating-point-opt]
```
Since they're a little annoying to suppress and will go away when updating to
the latest XCode version, we'll ignore these warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
36 - Build Build related PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(distutils) The -ffp-exception-behavior=strict setting does not actually work (reliably)
3 participants