This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][NFC] Fix suspicious bitwise expression in PrintBTEntry()
ClosedPublic

Authored by fixathon on Aug 5 2022, 10:20 PM.

Details

Summary

Current application of bitwise-OR to a binary mask always results in True, which seems
inconsistent with the intent of the statement, a likely typo.

Diff Detail

Event Timeline

fixathon created this revision.Aug 5 2022, 10:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 10:20 PM
fixathon requested review of this revision.Aug 5 2022, 10:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 10:20 PM
hawkinsw added inline comments.
lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
66

According to https://en.cppreference.com/w/cpp/language/operator_precedence, I would read the left operand of the && as

  1. The == has higher precedence than || so, b = (lbound == one_compl64)
  2. b || one_cmpl32

which does not seem like what the original author intended. I absolutely think that the fix is correct, but I just wanted to get everyone's feedback on whether this seems like more than just a "suspicious bitwise expression" (and more like a "mistaken bitwise expression").

All that said, I could be completely, 100% wrong. And, if I am, feel free to ignore me!

The original change was https://reviews.llvm.org/D29078. Are you able to run the tests with this applied?

lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
66

The corrected code also makes sense given that MPX is some kind of memory protection across ranges.

If ((lbound == one_cmpl64 || lbound == one_cmpl32) && ubound == 0) is true then upper bound < lower bound making an invalid range. Which is what I'd expect for some default/uninitialised state (especially if zero size ranges are allowed, so upper == 0 and lower == 0 couldn't be used).

hawkinsw added inline comments.Aug 8 2022, 5:57 AM
lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
66

@DavidSpickett I think that you and I are saying the same thing, right? We are both saying that the corrected code looks much "better" than the original?

Will

DavidSpickett added inline comments.Aug 8 2022, 6:05 AM
lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
66

We are both saying that the corrected code looks much "better" than the original?

Yes.

whether this seems like more than just a "suspicious bitwise expression" (and more like a "mistaken bitwise expression").

Definitely a mistake that needs correcting.

DavidSpickett added inline comments.Aug 8 2022, 6:07 AM
lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
66

(I think "suspicious bitwise expression" is what the static analyser would call it just because it can't be 100% sure it is wrong)

This revision was not accepted when it landed; it landed in state Needs Review.Aug 8 2022, 9:04 AM
This revision was automatically updated to reflect the committed changes.
fixathon marked an inline comment as done.