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

Address more Clang warnings #17506

Merged
merged 5 commits into from
Jan 21, 2025
Merged

Address more Clang warnings #17506

merged 5 commits into from
Jan 21, 2025

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 18, 2025

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.

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.
ext/gd/libgd/gd_interpolation.c Outdated Show resolved Hide resolved
main/streams/plain_wrapper.c Outdated Show resolved Hide resolved
@cmb69 cmb69 marked this pull request as ready for review January 18, 2025 13:06
Copy link
Member

@nielsdos nielsdos left a 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

ext/ffi/ffi.c Outdated Show resolved Hide resolved
Copy link
Member Author

@cmb69 cmb69 left a 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.

ext/com_dotnet/com_wrapper.c Outdated Show resolved Hide resolved
ext/ffi/ffi.c Outdated Show resolved Hide resolved
@bukka
Copy link
Member

bukka commented Jan 19, 2025

just not sure about the socket thing in plain_wrapper.c

Let's leave it for now. See also @bukka's comment.

Created a new issue for this: #17524

@@ -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:
Copy link
Member

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?

Copy link
Member

@nielsdos nielsdos Jan 20, 2025

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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)

Copy link
Member

@nielsdos nielsdos left a 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

@cmb69 cmb69 merged commit aa76127 into php:master Jan 21, 2025
10 checks passed
@cmb69
Copy link
Member Author

cmb69 commented Jan 21, 2025

Yeah, let's merge; there are still so many warnings to address.

@cmb69 cmb69 deleted the cmb/clang-warnings branch January 21, 2025 19:08
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.

6 participants