-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Address more Clang warnings #17506
Address more Clang warnings #17506
Conversation
We prefer clean solutions (such as declaring the proper type in the first place, or introducing a portable format specifier) where easily possible, but resort to casts otherwise.
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.
Looks right, just not sure about the socket thing in plain_wrapper.c
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.
just not sure about the socket thing in plain_wrapper.c
Let's leave it for now. See also @bukka's comment.
@@ -353,7 +353,7 @@ static zend_function *com_method_get(zend_object **object_ptr, zend_string *name | |||
ITypeComp_Release(bindptr.lptcomp); | |||
break; | |||
|
|||
case DESCKIND_NONE: | |||
default: |
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.
Perhaps EMPTY_SWITCH_DEFAULT_CASE()
instead?
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.
That macro is a misnomer and dangerous, it asserts the path is unreachable
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.
it asserts the path is unreachable
Yes and this seems to be the desired behavior here. The documentation indicates that only the 4 DESCKIND_*
cases that were previously handled may be returned. I'd rather crash if a new case appears instead of silently doing the wrong thing with it.
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.
The thing is, you won't necessarily crash. Anything can happen because taking an unreachable path is UB. This can either result in taking the wrong case or doing something completely absurd.
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.
Remember that assertions are turned into assumes in release builds.
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.
I'd be fine with an assert()
, but __assume()
is dangerous, it's comparable to UB, if applied at the wrong place, and I wouldn't fully trust that documentation. Maybe in this case it is better to explicitly list the alternatives, and add a ZEND_ASSERT(0)
there.
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.
ZEND_ASSERT(0)
essentially would do the same thing as marking it unreachable. I'd be okay with assert(0)
but I predict someone's gonna turn that into ZEND_ASSERT
on refactor in the future. ZEND_ASSERT
is turned into an assume, and with 0 as an argument it's an assume on something that's false, the compiler can do anything. Can we please not do dangerous programming?
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.
D'oh! Of course, you're right.
Maybe we should actually change ZEND_ASSERT()
to not be ZEND_ASSUME()
in non-debug builds, and use ZEND_ASSUME()
directly, where we are absolutely sure that the code is unreachable (in which case we can likely drop such code, and maybe address compiler warnings by other means). Or something like that.
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.
I did not know the difference between assume and assert, for me the assertions are there to ensure in debug builds that the preconditions, or the current state is what you expect it to be.
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.
Transforming assertions into assumes was done on purpose during the phpng development: e1ab2cf
Changing that would have a performance impact as people specifically use it in that way (debug time assertions, production time optimizations)
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.
ok as-is for me
Yeah, let's merge; there are still so many warnings to address. |
We prefer clean solutions (such as declaring the proper type in the first place, or introducing a portable format specifier) where easily possible, but resort to casts otherwise.