This is an archive of the discontinued LLVM Phabricator instance.

Fix const-correctness in RegisterContext methods, NFC
ClosedPublic

Authored by vsk on Dec 4 2017, 5:43 PM.

Details

Summary

A few methods in RegisterContext classes accept const objects which are
cast to a non-const thread_state_t. Drop const-ness more explicitly
where we mean to do so. This fixes a slew of warnings.

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Dec 4 2017, 5:43 PM

Seems wrong to remove the const on structs that don't need to change in order to make the write happen. Can't we just quiet the warnings with a const_cast inside the function call?

vsk added a comment.Dec 5 2017, 11:00 AM

Seems wrong to remove the const on structs that don't need to change in order to make the write happen. Can't we just quiet the warnings with a const_cast inside the function call?

Absolutely. I opted for dropping const to make the DoRead* and DoWrite* methods feel consistent. At first glance, it looked like there may be methods in RegisterContext which expect non-const GPR/FPU/etc objects, so it seemed reasonable to drop const.

I'm open to just adding in the const_cast<X>(static_cast<const X>(...)) pattern as needed to suppress warnings, and to constifying the rest of RegisterContext as a follow-up. Let me know what you'd prefer.

In D40821#945379, @vsk wrote:

Seems wrong to remove the const on structs that don't need to change in order to make the write happen. Can't we just quiet the warnings with a const_cast inside the function call?

Absolutely. I opted for dropping const to make the DoRead* and DoWrite* methods feel consistent. At first glance, it looked like there may be methods in RegisterContext which expect non-const GPR/FPU/etc objects, so it seemed reasonable to drop const.

I'm open to just adding in the const_cast<X>(static_cast<const X>(...)) pattern as needed to suppress warnings, and to constifying the rest of RegisterContext as a follow-up. Let me know what you'd prefer.

Please do that as it makes more sense API wise.

vsk updated this revision to Diff 125639.Dec 5 2017, 3:36 PM
vsk edited the summary of this revision. (Show Details)
  • Address Greg's comments.
vsk added a reviewer: clayborg.Dec 5 2017, 3:36 PM
clayborg accepted this revision.Dec 5 2017, 3:40 PM
This revision is now accepted and ready to land.Dec 5 2017, 3:40 PM
This revision was automatically updated to reflect the committed changes.