This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFC] Use static_cast instead of reinterpret_cast where possible
ClosedPublic

Authored by teemperor on Jan 3 2020, 8:04 AM.

Details

Summary

There are a few places in LLDB where we do a reinterpret_cast for conversions that we could also do with static_cast. This patch moves all this code to static_cast.

Diff Detail

Event Timeline

teemperor created this revision.Jan 3 2020, 8:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2020, 8:04 AM
shafik added inline comments.Jan 3 2020, 11:20 AM
lldb/tools/debugserver/source/MacOSX/MachProcess.mm
1745

static_cast<uint64_t>(addr) and static_cast<uint64_t>(length)

1777

static_cast<uint64_t>(addr) and static_cast<uint64_t>(length)

You can use -Wold-style-cast to warm on C-style casts.

2306

static_cast<uint64_t>(buf_size)

2466

static_cast<uint64_t>(buf_size)

This is a great change! Moving to stricter casts clarifies intent and reduces the chance that later changes can introduce bugs accidentally.

labath accepted this revision.Jan 6 2020, 7:02 AM

cool

This revision is now accepted and ready to land.Jan 6 2020, 7:02 AM
teemperor marked an inline comment as done.Jan 7 2020, 3:27 AM
teemperor added inline comments.
lldb/tools/debugserver/source/MacOSX/MachProcess.mm
1745

Uhm, I agree with removing those C casts, but I don't want to start removing a few random C casts in a patch that is about removing reinterpret_cast (and you anyway already opened a review for removing C casts). I'll can make a separate patch for all the C casts (or we could fix those APIs to not be unsafe variadic functions which would remove the need to cast everything).

This revision was automatically updated to reflect the committed changes.