-
Notifications
You must be signed in to change notification settings - Fork 15k
[compiler-rt] Restore unsigned value in struct, use enum only in function #165048
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
base: main
Are you sure you want to change the base?
[compiler-rt] Restore unsigned value in struct, use enum only in function #165048
Conversation
| if (Type != CPU_TYPE_MAX) | ||
| __cpu_model.__cpu_type = Type; | ||
| if (Subtype != CPU_SUBTYPE_MAX) | ||
| __cpu_model.__cpu_subtype = Subtype; |
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.
Likewise
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 don't follow, I think one of your comments wasn't posted
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.
Ugh, silly GitHub. I was thinking early return might be useful here.
| if (Type != CPU_TYPE_MAX) | ||
| __cpu_model.__cpu_type = Type; | ||
| if (Subtype != CPU_SUBTYPE_MAX) | ||
| __cpu_model.__cpu_subtype = Subtype; | ||
|
|
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 won't block the PR but I don't like this kind of refactor. Previously it was a pure static function that touched no context. Now it implicitly modifies the global variable. References to __cpu_type and __cpu_subtype were additional return values.
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 understand the downsides, but I believe in this file it's not gonna be a problem, especially how the function is local.
I can refactor later to not use the global like that, but the previous solution of passing a pointer to some fields of the global isn't much different than what the code is doing now
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 commented on my original PR that passing pointers to field while assuming a different signedness is not good. What about passing pointers to entire struct? That would required the struct to be named but I think we should be fine by 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.
Yeah, passing the pointer to the struct would be my preference as well.
Typed enums are c23 features and are too new to be used. This PR restores the types in the
__processor_modelstruct back tounsigned int, removes typed enums, and uses the enum in the function as a variable that's later assigned to a global in order to prevent errors fixed initially here: #164713See #165034 for more background