Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Remove dead code block (NFC) #94775

Merged
merged 1 commit into from
Jun 15, 2024
Merged

[lldb] Remove dead code block (NFC) #94775

merged 1 commit into from
Jun 15, 2024

Conversation

xgupta
Copy link
Contributor

@xgupta xgupta commented Jun 7, 2024

The check that max_bit_pos == sign_bit_pos conflicts with the check that sign_bit_pos < max_bit_pos in the block surrounding it.

Originally found by cppcheck -
lldb/source/Utility/Scalar.cpp:756:23: warning: Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]

Fixes #85985

@xgupta xgupta requested a review from JDevlieghere as a code owner June 7, 2024 17:46
@xgupta xgupta requested a review from clayborg June 7, 2024 17:47
@llvmbot llvmbot added the lldb label Jun 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 7, 2024

@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)

Changes

Fixes #85985

lldb/source/Utility/Scalar.cpp:756:23: warning: Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]


Full diff: https://github.com/llvm/llvm-project/pull/94775.diff

1 Files Affected:

  • (modified) lldb/source/Utility/Scalar.cpp (+1-3)
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c70c5e1079918..c680101aa9efa 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -753,9 +753,7 @@ bool Scalar::SignExtend(uint32_t sign_bit_pos) {
       return false;
 
     case Scalar::e_int:
-      if (max_bit_pos == sign_bit_pos)
-        return true;
-      else if (sign_bit_pos < (max_bit_pos - 1)) {
+      if (sign_bit_pos < (max_bit_pos - 1)) {
         llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
         llvm::APInt bitwize_and = m_integer & sign_bit;
         if (bitwize_and.getBoolValue()) {

@JDevlieghere
Copy link
Member

JDevlieghere commented Jun 7, 2024

The change LGTM, but I have a few suggestions regarding the title and description:

  • Retitle the PR to something like "[lldb] Remove dead code block (NFC)" or something that conveys the intent/outcome. The modified file and line number are already part of the commit and are just redundant. You could mention it was found by cppcheck if you think that's useful.
  • Update the description to explain why this code block is dead. Something along the lines of "The check that max_bit_pos == sign_bit_pos conflicts with the check that sign_bit_pos < max_bit_pos in the block surrounding it" or something like that. Definitely mention the issue but don't just repeat the warning without enough context to make sense of it.

@xgupta
Copy link
Contributor Author

xgupta commented Jun 7, 2024

The change LGTM, but I have a few suggestions regarding the title and description:

Retitle the PR to something like "[lldb] Remove dead code block (NFC)" or something that conveys the intent/outcome. The modified file and line number are already part of the commit and are just redundant. You could mention it was found by cppcheck if you think that's useful.

Update the description to explain why this code block is dead. Something along the lines of "The check that max_bit_pos == sign_bit_pos conflicts with the check that sign_bit_pos < max_bit_pos in the block surrounding it" or something like that. Definitely mention the issue but don't just repeat the warning without enough context to make sense of it.

Thanks, will update other PRs also as you suggested.

@xgupta xgupta changed the title [LLDB] [NFC] Fix a cppcheck warning in lldb/source/Utility/Scalar.cpp [lldb] Remove dead code block (NFC) Jun 8, 2024
@xgupta
Copy link
Contributor Author

xgupta commented Jun 15, 2024

gentle ping!

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@xgupta xgupta merged commit ef01c75 into llvm:main Jun 15, 2024
7 checks passed
@fmayer
Copy link
Contributor

fmayer commented Jun 15, 2024

Random drive-by:

The check that max_bit_pos == sign_bit_pos conflicts with the check that sign_bit_pos < max_bit_pos in the block surrounding it.

Should we add an assert to this function then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lldb/source/Utility/Scalar.cpp:756: Condition can never be true
4 participants