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

Use __builtin_unreachable() for ZEND_UNREACHABLE #12248

Closed
wants to merge 1 commit into from

Conversation

iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Sep 20, 2023

__builtin_assume() is only supported on Clang. __builtin_unreachable() may provide additional hints to GCC.

More accurately, on GCC the code if (__builtin_expect(!(0), 0)) __builtin_unreachable(); is generated for unreachable. However, GCC does not seem to accurately mark the path as unreachable due to the if statement. Removing it fixes the warning.

Motivated by the compile error in https://github.com/php/php-src/actions/runs/6242795686/job/16947298463.

/cc @TimWolla

__builtin_assume() is only supported on Clang. __builtin_unreachable() may
provide additional hints to GCC.
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently ZEND_ASSUME() already has a variant that is based on __builtin_unreachable, but the updated semantics clearly make sense.

With regard to the updated implementation of php_round_helper, it will need an update anyway, because nothing currently validates the rounding mode, thus round(0, mode: 9) crashes.

@iluuu1994
Copy link
Member Author

Right, I didn't look closely enough. For some reason, if (__builtin_expect(!(0), 0)) __builtin_unreachable(); doesn't make GCC happy, but __builtin_unreachable() alone does. assert(0); doesn't work either. I'm not sure if it makes a difference in the actual code generation.

@iluuu1994 iluuu1994 closed this in 37ce719 Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants