This is an archive of the discontinued LLVM Phabricator instance.

Removing C-style casts in favor of explict C++ style casts
Needs ReviewPublic

Authored by shafik on Jan 3 2020, 4:44 PM.

Details

Summary

C-style casts hide intent and when code changes they can also hide logic errors.

This change converts most of the C-style cast into static_cast and the icky ones are converted to reinterpret_cast and we can deal with fixing those icky cases in another change.

One case was moved to use std::numeric_limits<unsigned>::max() since it was simply using the fact that -1 converted to unsigned results in the maximum unsigned value.

Diff Detail

Event Timeline

shafik created this revision.Jan 3 2020, 4:44 PM
labath added a comment.Jan 6 2020, 7:16 AM

This is fine, though, since you're already touching these lines, I'd consider converting them from LLDB_LOGF to LLDB_LOG at the same time (getting rid of most of the static_casts...).

However, I don't think we should be changing (void) to static_cast<void>.

There is also ample precedent in llvm for using -1 (or sometimes ~0) to mean UINTxx_MAX, so I'm not sure we should change that too. Though it is somewhat confusing, in a way, it is actually safer, as -1 will always convert to the right MAX value. (e.g., in foo = -1, the value will remain fff...ff even if we change the type of foo from uint32_t to uint64_t, but that won't happen with UINT32_MAX)...

lldb/source/Expression/IRExecutionUnit.cpp
306–307

I think this is overkill. (void) is used throughout llvm as a way to explicitly ignore a value (usually done to supress some kind of a warning).

This is fine, though, since you're already touching these lines, I'd consider converting them from LLDB_LOGF to LLDB_LOG at the same time (getting rid of most of the static_casts...).

+1 :-)

teemperor added inline comments.Jan 8 2020, 9:40 AM
lldb/include/lldb/Expression/IRExecutionUnit.h
330

Do we even need this cast? Neither Clang nor GCC complain about unsigned X = -1 for me.