Skip to content

Conversation

@yuxuanchen1997
Copy link
Member

@yuxuanchen1997 yuxuanchen1997 commented Oct 24, 2025

This unsigned int here is a new addition introduced in #164713 and doesn't compile under older (<13) gcc (see godbolt), which LLVM officially supports from 7.4+. This change should be fine as none of the enum values are negative.

@compnerd
Copy link
Member

compnerd commented Oct 24, 2025

This isn't fine sadly - the signedness is platform specific. This needs to be preserved. I think that requiring GCC 13+ is acceptable. This is not building LLVM, it is target code.

@yuxuanchen1997
Copy link
Member Author

yuxuanchen1997 commented Oct 24, 2025

This isn't fine sadly - the signedness is platform specific. This needs to be preserved. I think that requiring GCC 7+ is acceptable.

Sorry if I didn't make it clear. I am trying to say that the enum doesn't need to be unsigned int. It used to be just int before #164713. This code used enum-type-specifier which is going to push GCC requirement to 13+ from the current 7+.

@yuxuanchen1997 yuxuanchen1997 changed the title [compiler-rt] fix gcc <13 support by removing enum-type-specifier [compiler-rt] fix gcc 12 support by removing enum-type-specifier Oct 24, 2025
@compnerd
Copy link
Member

This isn't fine sadly - the signedness is platform specific. This needs to be preserved. I think that requiring GCC 7+ is acceptable.

Sorry if I didn't make it clear. I am trying to say that the enum doesn't need to be unsigned int. It used to be just int before #164713. This code used enum-type-specifier which is going to push GCC requirement to 13+ from the current 7+.

But it does. The recent change changed the struct member from unsigned int to the enumerator type. If you want to make this ABI compliant, I think that we should revert the change to the struct to use the unsigned int.

@mikolaj-pirog
Copy link
Member

Thanks @yuxuanchen1997 for pointing out that using typed enums is c23, I missed that.

My goal with introducing the enum was to prevent errors like the one I fixed in the PR with CWF. I think we could keep the enum as an argument type, revert to unsigned int in the struct, and cast when calling the function. Would that be okay?

@yuxuanchen1997
Copy link
Member Author

If you want to make this ABI compliant, I think that we should revert the change to the struct to use the unsigned int.

Would be in favor of that solution.

@yuxuanchen1997
Copy link
Member Author

Thanks @yuxuanchen1997 for pointing out that using typed enums is c23, I missed that.

My goal with introducing the enum was to prevent errors like the one I fixed in the PR with CWF. I think we could keep the enum as an argument type, revert to unsigned int in the struct, and cast when calling the function. Would that be okay?

Thanks. That would be ok for me.

@compnerd
Copy link
Member

Thanks @yuxuanchen1997 for pointing out that using typed enums is c23, I missed that.

My goal with introducing the enum was to prevent errors like the one I fixed in the PR with CWF. I think we could keep the enum as an argument type, revert to unsigned int in the struct, and cast when calling the function. Would that be okay?

Yeah, that would be fine. I don't have a strong opinion between the two as long as the ABI is not changed.

@mikolaj-pirog
Copy link
Member

Alright, I can file a PR with a fix shortly

@yuxuanchen1997
Copy link
Member Author

yuxuanchen1997 commented Oct 24, 2025

Thanks @yuxuanchen1997 for pointing out that using typed enums is c23, I missed that.

My goal with introducing the enum was to prevent errors like the one I fixed in the PR with CWF. I think we could keep the enum as an argument type, revert to unsigned int in the struct, and cast when calling the function. Would that be okay?

Double checking this... You probably still have (some theoretical) ABI issues if the enums are used as arguments to getIntelProcessorTypeAndSubtype and getAMDProcessorTypeAndSubtype. Having pointers to signed enum as arguments, the two functions will do a signed to signed assignment by treating the argument pointer as one to a signed int, where the caller has passed one to an unsigned int. I think ideally you'd want to preserve that signed to unsigned assignment if you want to be able to pass &(__cpu_model.__cpu_type).

@compnerd
Copy link
Member

compnerd commented Oct 24, 2025

Thanks @yuxuanchen1997 for pointing out that using typed enums is c23, I missed that.
My goal with introducing the enum was to prevent errors like the one I fixed in the PR with CWF. I think we could keep the enum as an argument type, revert to unsigned int in the struct, and cast when calling the function. Would that be okay?

Double checking this... You probably still have (some theoretical) ABI issues if the enums are used as arguments to getIntelProcessorTypeAndSubtype and getAMDProcessorTypeAndSubtype. Having pointers to signed enum as arguments, the two functions will do a signed to signed assignment by treating the argument pointer as one to a signed int, where the caller has passed one to an unsigned int. I think ideally you'd want to preserve that signed to unsigned assignment if you want to be able to pass &(__cpu_model.__cpu_type).

Correct, but the members of the structure is more what I was concerned about. The other functions should be fine (they shouldn't be used outside of the module).

@mikolaj-pirog
Copy link
Member

Here's a PR #165048

mikolaj-pirog added a commit that referenced this pull request Oct 26, 2025
…tion (#165048)

Typed enums are c23 features and are too new to be used. This PR
restores the types in the `__processor_model` struct back to `unsigned
int`, removes typed enums, and uses the enum in the function as a
variable that's later assigned to a struct in order to prevent errors
fixed initially here: #164713

See #165034 for more background
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 26, 2025
…nly in function (#165048)

Typed enums are c23 features and are too new to be used. This PR
restores the types in the `__processor_model` struct back to `unsigned
int`, removes typed enums, and uses the enum in the function as a
variable that's later assigned to a struct in order to prevent errors
fixed initially here: #164713

See llvm/llvm-project#165034 for more background
varun-r-mallya pushed a commit to varun-r-mallya/llvm-project that referenced this pull request Oct 27, 2025
…tion (llvm#165048)

Typed enums are c23 features and are too new to be used. This PR
restores the types in the `__processor_model` struct back to `unsigned
int`, removes typed enums, and uses the enum in the function as a
variable that's later assigned to a struct in order to prevent errors
fixed initially here: llvm#164713

See llvm#165034 for more background
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
…tion (llvm#165048)

Typed enums are c23 features and are too new to be used. This PR
restores the types in the `__processor_model` struct back to `unsigned
int`, removes typed enums, and uses the enum in the function as a
variable that's later assigned to a struct in order to prevent errors
fixed initially here: llvm#164713

See llvm#165034 for more background
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.

4 participants