This is an archive of the discontinued LLVM Phabricator instance.

[LLDB] Missing break in a switch statement alters the execution flow.
AbandonedPublic

Authored by fixathon on Aug 5 2022, 12:36 AM.

Details

Summary

Looks like a typo from the past code changes.

Diff Detail

Event Timeline

fixathon created this revision.Aug 5 2022, 12:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 12:36 AM
fixathon requested review of this revision.Aug 5 2022, 12:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 12:36 AM

Added in-code comments with details

lldb/source/Plugins/Process/Utility/ARMUtils.h
48–49

These lines were unreachable prior to the fix due to the default label with no break skipping to case 0. Past code history suggests that was accidental.

314–315

Same here. Past code history suggests the break was missing by accident, i.e the default case was added to satisfy a static code checker without the intent to modify the execution flow.

DavidSpickett added inline comments.Aug 5 2022, 1:51 AM
lldb/source/Plugins/Process/Utility/ARMUtils.h
29

Looking at the codepaths and the reason this function exists, it's either called with a 2 bit number which is the "type" field of an instruction, or it's not called because the type is known to be SRType_RRX already.

In the enum ARM_ShifterType SRType_RRX would be 4, which wouldn't fit the 2 bit expectation.

So I think we can safely re-enable this assert and move the two unreachable lines up here. I didn't get any test failures doing so and I don't see a codepath that could hit it.

(but it would be fairly easy for future changes to make this mistake since it's not very obvious from the types, so an assert is good here)

314–315

This part LGTM. This "bits" function is returning uint32 so the compiler can't know it'll only be in a 2 bit range.

fixathon updated this revision to Diff 450460.Aug 5 2022, 6:45 PM

Addressed comments

fixathon updated this revision to Diff 450466.Aug 5 2022, 8:36 PM

Code update to address the comments

Differential Revision: https://reviews.llvm.org/D131244

DavidSpickett added inline comments.Aug 8 2022, 1:21 AM
lldb/source/Plugins/Process/Utility/ARMUtils.h
49

This is now dead code?

fixathon marked an inline comment as done.Aug 8 2022, 8:57 AM
fixathon added inline comments.
lldb/source/Plugins/Process/Utility/ARMUtils.h
29

Added the assert back

49

This will execute for the default case after its break.

fixathon abandoned this revision.Aug 8 2022, 9:35 AM
fixathon marked an inline comment as done.

closing as already patched.