-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Automatically check that VERIFY_CHECKs are side effect free #904
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack 07d1a6e
Nice trick using autotools to detect whether the shouldn't_survive variable would actually survive or not!
I like this approach because it's safe and we let the compiler prove things. I have a few minor suggestions (will post these later). I'm somewhat concerned that there may be compiler (flags) in the wild that make the autoconf check pass but still fail on the real examples in our code base. It's somewhat hard to predict. Of course this wouldn't be terrible. We could try and see if we get those reports. Maybe a more conservative approach would be to restrict it to gcc and clang, or to have a |
9e199b4
to
d097da2
Compare
A few changes:
|
I still seems to fail with ubsan. I guess ubsan disables some optimizations (there could be UB in the eliminated code). Is there a specific reason to disable this on clang? |
d097da2
to
fb87eb6
Compare
Pushed a change to make it 'auto' for those (which for the time being probably means 'no').
Yes, CI failed. Apparently clang's optimizer isn't powerful enough for the auto-detect test I have now. |
(I reported the MacOS failures at cirruslabs/macos-image-templates#33 (comment) .) |
Are you sure? I don't see any failure here in the previous CI runs that seems specific to clang https://cirrus-ci.com/github/bitcoin-core/secp256k1/pull/904. My local clang 11.1 seems clever enough to optimize it (ok that does not say much -- the Debian image on CI has clang 7...) |
fb87eb6
to
a21ead0
Compare
@real-or-random Trying without EDIT: seems it's fine. |
a21ead0
to
75234ab
Compare
If it works properly on all mainstream compilers then it's pretty cool :) But this worry isn't substantiated by anything. |
|
@real-or-random Oopps should've read the whole thread and not just the OP 😅 |
Here's a slightly improved definition that (on GCC) gives a diagnostic which is readable and is given at compile-time instead of link time.
(On compiler explorer to play around with this: https://gcc.godbolt.org/z/hhhxsb9T9) It's a little bit strange because GCC has this As a nit, I'd prefer |
I believe this isn't the way to go. It's a nice idea, but in practice, our code has been accumulating more and more |
Alternative to #902 (but contains part of it).
Permit a configure-time option to use a trick to let the compiler prove our
VERIFY_CHECK
statements are side-effect free. See details on https://stackoverflow.com/a/35294344, and was suggested on #902 (comment).This is default off in order to not break builds on untested platforms (which may have different sensitivity for this kind of optimization). It can be set to auto as well, to let the configure script figure out if the compiler (and current compilation flag) permit usage of this.