[Lldb-commits] [lldb] [LLDB] Remove the redundent increment of 'properties' variable (PR #95675)

2024-06-15 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta created 
https://github.com/llvm/llvm-project/pull/95675

This is described in (N3) https://pvs-studio.com/en/blog/posts/cpp/1126/ so 
caught by the PVS Studio analyzer. Warning message -
V547 Expression 'properties ++ > 0' is always false. CommandObjectTarget.cpp:100

I could not understand it properly but the properties++ operation is performed 
twice when the target architecture is valid.
First increment seems unnecessary since it is always false '0>0'.

>From a305b3958b3bf5551fda2d17af8eb11b9d122125 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sat, 15 Jun 2024 23:12:19 +0530
Subject: [PATCH] [LLDB] Remove the redundent increment of 'properties'
 variable

This is described in (N3) https://pvs-studio.com/en/blog/posts/cpp/1126/ so 
caught by the PVS Studio analyzer.
Warning message -
V547 Expression 'properties ++ > 0' is always false. CommandObjectTarget.cpp:100

I could not understand it properly but the properties++ operation is performed
twice when the target architecture is valid.
First increment seems unnecessary since it is always false '0>0'.
---
 lldb/source/Commands/CommandObjectTarget.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index ae6c6d5479a19..c3d4307267a1b 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -97,7 +97,7 @@ static void DumpTargetInfo(uint32_t target_idx, Target 
*target,
 
   uint32_t properties = 0;
   if (target_arch.IsValid()) {
-strm.Printf("%sarch=", properties++ > 0 ? ", " : " ( ");
+strm.Printf("%sarch=", properties > 0 ? ", " : " ( ");
 target_arch.DumpTriple(strm.AsRawOstream());
 properties++;
   }

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Remove the redundent increment of 'properties' variable (PR #95675)

2024-06-15 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)


Changes

This is described in (N3) https://pvs-studio.com/en/blog/posts/cpp/1126/ so 
caught by the PVS Studio analyzer. Warning message -
V547 Expression 'properties ++ > 0' is always false. 
CommandObjectTarget.cpp:100

I could not understand it properly but the properties++ operation is performed 
twice when the target architecture is valid.
First increment seems unnecessary since it is always false '0>0'.

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


1 Files Affected:

- (modified) lldb/source/Commands/CommandObjectTarget.cpp (+1-1) 


``diff
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index ae6c6d5479a19..c3d4307267a1b 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -97,7 +97,7 @@ static void DumpTargetInfo(uint32_t target_idx, Target 
*target,
 
   uint32_t properties = 0;
   if (target_arch.IsValid()) {
-strm.Printf("%sarch=", properties++ > 0 ? ", " : " ( ");
+strm.Printf("%sarch=", properties > 0 ? ", " : " ( ");
 target_arch.DumpTriple(strm.AsRawOstream());
 properties++;
   }

``




https://github.com/llvm/llvm-project/pull/95675
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)

2024-06-15 Thread Shivam Gupta via lldb-commits

xgupta wrote:

Gentile ping!

https://github.com/llvm/llvm-project/pull/94775
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix incorrect logical operator in 'if' condition check (NFC) (PR #94779)

2024-06-15 Thread Shivam Gupta via lldb-commits

xgupta wrote:

Gentile ping!

https://github.com/llvm/llvm-project/pull/94779
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)

2024-06-15 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/94775
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)

2024-06-15 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta closed https://github.com/llvm/llvm-project/pull/94775
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] ef01c75 - [lldb] Remove dead code block (NFC) (#94775)

2024-06-15 Thread via lldb-commits

Author: Shivam Gupta
Date: 2024-06-15T23:39:58+05:30
New Revision: ef01c75d467df92b8c659307595aa74ed2290cd8

URL: 
https://github.com/llvm/llvm-project/commit/ef01c75d467df92b8c659307595aa74ed2290cd8
DIFF: 
https://github.com/llvm/llvm-project/commit/ef01c75d467df92b8c659307595aa74ed2290cd8.diff

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

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

Added: 


Modified: 
lldb/source/Utility/Scalar.cpp

Removed: 




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()) {



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)

2024-06-15 Thread Florian Mayer via lldb-commits

fmayer wrote:

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?

https://github.com/llvm/llvm-project/pull/94775
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Correct format specifier for sscanf to prevent buffer overflow (NFC) (PR #94783)

2024-06-15 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/94783

>From 17d39d89ee723881063ecbea19caaa6806e4e095 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sat, 15 Jun 2024 23:57:03 +0530
Subject: [PATCH] Resolved merge conflict

---
 lldb/source/Host/linux/Host.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 5545f9ef4d70e..8a38947d4b665 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -100,7 +100,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
&ProcessInfo,
   StatFields stat_fields;
   if (sscanf(
   Rest.data(),
-  "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
+  "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld 
%ld",
   &stat_fields.pid, stat_fields.comm, &stat_fields.state,
   &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
   &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Correct format specifier for sscanf to prevent buffer overflow (NFC) (PR #94783)

2024-06-15 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff ef01c75d467df92b8c659307595aa74ed2290cd8 
17d39d89ee723881063ecbea19caaa6806e4e095 -- lldb/source/Host/linux/Host.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 8a38947d4b..b5fa266da1 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -98,16 +98,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
&ProcessInfo,
   if (Rest.empty())
 return false;
   StatFields stat_fields;
-  if (sscanf(
-  Rest.data(),
-  "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld 
%ld",
-  &stat_fields.pid, stat_fields.comm, &stat_fields.state,
-  &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
-  &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,
-  &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt,
-  &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime,
-  &stat_fields.cutime, &stat_fields.cstime,
-  &stat_fields.realtime_priority, &stat_fields.priority) < 0) {
+  if (sscanf(Rest.data(),
+ "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld 
"
+ "%ld",
+ &stat_fields.pid, stat_fields.comm, &stat_fields.state,
+ &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
+ &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,
+ &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt,
+ &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime,
+ &stat_fields.cutime, &stat_fields.cstime,
+ &stat_fields.realtime_priority, &stat_fields.priority) < 0) {
 return false;
   }
 

``




https://github.com/llvm/llvm-project/pull/94783
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add an assert to verify sign_bit_pos is within the valid range (NFC) (PR #95678)

2024-06-15 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta created 
https://github.com/llvm/llvm-project/pull/95678

None

>From 74efb6ae3187fe1e67e61cdca1f99b9de8146db4 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sun, 16 Jun 2024 00:21:51 +0530
Subject: [PATCH] [LLDB] Add an assert to verify sign_bit_pos is within the
 valid range

---
 lldb/source/Utility/Scalar.cpp | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c680101aa9efa..6e2f1ca4c1613 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -745,26 +745,25 @@ Status Scalar::SetValueFromData(const DataExtractor &data,
 
 bool Scalar::SignExtend(uint32_t sign_bit_pos) {
   const uint32_t max_bit_pos = GetByteSize() * 8;
+  assert(sign_bit_pos < max_bit_pos);
 
-  if (sign_bit_pos < max_bit_pos) {
-switch (m_type) {
-case Scalar::e_void:
-case Scalar::e_float:
-  return false;
+  switch (m_type) {
+  case Scalar::e_void:
+  case Scalar::e_float:
+return false;
 
-case Scalar::e_int:
-  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()) {
-  llvm::APInt mask =
-  ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
-  m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
-}
-return true;
+  case Scalar::e_int:
+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()) {
+llvm::APInt mask =
+~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
   }
-  break;
+  return true;
 }
+break;
   }
   return false;
 }

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add an assert to verify sign_bit_pos is within the valid range (NFC) (PR #95678)

2024-06-15 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)


Changes



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


1 Files Affected:

- (modified) lldb/source/Utility/Scalar.cpp (+15-16) 


``diff
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c680101aa9efa..6e2f1ca4c1613 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -745,26 +745,25 @@ Status Scalar::SetValueFromData(const DataExtractor &data,
 
 bool Scalar::SignExtend(uint32_t sign_bit_pos) {
   const uint32_t max_bit_pos = GetByteSize() * 8;
+  assert(sign_bit_pos < max_bit_pos);
 
-  if (sign_bit_pos < max_bit_pos) {
-switch (m_type) {
-case Scalar::e_void:
-case Scalar::e_float:
-  return false;
+  switch (m_type) {
+  case Scalar::e_void:
+  case Scalar::e_float:
+return false;
 
-case Scalar::e_int:
-  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()) {
-  llvm::APInt mask =
-  ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
-  m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
-}
-return true;
+  case Scalar::e_int:
+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()) {
+llvm::APInt mask =
+~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
   }
-  break;
+  return true;
 }
+break;
   }
   return false;
 }

``




https://github.com/llvm/llvm-project/pull/95678
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits