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

Fix ignored qualifiers #3266

Merged
merged 1 commit into from
Jan 11, 2025
Merged

Conversation

BsAtHome
Copy link
Contributor

Running the compile with -Wignored-qualifiers results in more warnings that indicate wrong types being used. This PR fixes two cases:

  • ignored volatile qualifier on cast
  • ignored const or volatile return qualifier

Returning const or volatile values is inappropriate, just like casting a value to volatile is inappropriate. The hal_X_t types are replaced with the underlying type and the const on return values is removed.

BTW, yes, I'm trying to eliminate all warnings from the compile.

Fix ignored volatile qualifier on cast.
@andypugh
Copy link
Collaborator

BTW, yes, I'm trying to eliminate all warnings from the compile.

I think I achieved that once (but at a lower level of compiler pedantry). I appreciate the effort.

@andypugh
Copy link
Collaborator

You have been in there a lot recently. What do you think would be the result of replacing all hal/rtapi_u32/u64 with hal/rtapi_unsigned and the same for signed, where hal_unsigned == u64.
Some HAL files using the dev version might have to change, but that could be handled by update_ini. Some components such as stepgen will need their internal accumulators looking at (in many cases these are already 64 bits, but they all should be to eliminate the risk of wrapping)

@andypugh andypugh merged commit a9ec62b into LinuxCNC:master Jan 11, 2025
10 checks passed
@BsAtHome
Copy link
Contributor Author

BTW, yes, I'm trying to eliminate all warnings from the compile.

I think I achieved that once (but at a lower level of compiler pedantry). I appreciate the effort.

Well, pedantry is necessary for optimal performance ;-)

More seriously, the codebase should compile warning free with -Wextra and then we also should add -Werror by default. There is no excuse for warnings. Warnings are (potential) bugs and generally bad coding practice. There is no need for any warning to be present, at all.

@BsAtHome
Copy link
Contributor Author

You have been in there a lot recently. What do you think would be the result of replacing all hal/rtapi_u32/u64 with hal/rtapi_unsigned and the same for signed, where hal_unsigned == u64.

I can see the argument, but I don't think it is a good idea. There is a reason for distinct types at the low level of interfacing done by parts of the code. This is, after all, real-time code, where speed should be considered. Therefore, it matters what type you use and how it is aligned.

The real problem is that a lot of code has been written without proper thought why a specific type is used. That is not only true for 32/64 sizes, but also indiscriminate use of signed/unsigned. Also, because the hal_X_t types are special, it matters how you use them (that goes both for atomicity and volatility). They are not normal variables and the compiler is in large part not allowed to optimize the code when you use them.

Just replacing 32 with 64 bit types does not help. You actually need to understand the problem you are trying to solve and pick the right types for the problem at hand.

Some HAL files using the dev version might have to change, but that could be handled by update_ini. Some components such as stepgen will need their internal accumulators looking at (in many cases these are already 64 bits, but they all should be to eliminate the risk of wrapping)

I think a complete review is in order with a clear strategy how this stuff should be coded. But I think we need to create an issue for hal and RT use and discuss the details there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants