[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-14 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-14 Thread David Spickett via lldb-commits

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

Thanks!

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-13 Thread via lldb-commits

https://github.com/aabhinavg updated 
https://github.com/llvm/llvm-project/pull/91882

>From 9b4160975efe059f39a842689b1f750a10453203 Mon Sep 17 00:00:00 2001
From: aabhinavg 
Date: Sun, 12 May 2024 12:42:59 +0530
Subject: [PATCH 1/2] Fix redundant condition in Target.cpp

This commit addresses issue #87244, where a redundant condition was found in 
the Target.cpp file.
Static analyzer cppcheck flagged the issue in the Target.cpp file
---
 lldb/source/Target/Target.cpp | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 82f3040e539a3..fe87728a33dc8 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  if (num_supported_hardware_watchpoints == 0) {
-error.SetErrorStringWithFormat(
-"Target supports (%u) hardware watchpoint slots.\n",
-*num_supported_hardware_watchpoints);
-return false;
-  }
+  // If num_supported_hardware_watchpoints is zero, set an 
+  //error message and return false.
+
+  error.SetErrorStringWithFormat(
+  "Target supports (%u) hardware watchpoint slots.\n",
+  *num_supported_hardware_watchpoints);
+  return false;
+  
   return true;
 }
 

>From 421b4eed4c8bbcc2777fcbee1bf6c27786a393de Mon Sep 17 00:00:00 2001
From: aabhinavg 
Date: Mon, 13 May 2024 21:25:58 +0530
Subject: [PATCH 2/2] Revert "Fix redundant condition in Target.cpp"

This reverts commit 9b4160975efe059f39a842689b1f750a10453203.

The CheckIfWatchpointsSupported function is refactored to maintain the intended 
behavior as described below:

1. If we can't detect hardware watchpoints, assume they are supported.
2. If we can detect hardware watchpoints and there are more than 0, return true.
3. If we can detect hardware watchpoints but there are 0 of them, set an error 
message and return false.

fix #87244
---
 lldb/source/Target/Target.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index fe87728a33dc8..77731167995e1 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,14 +841,12 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  // If num_supported_hardware_watchpoints is zero, set an 
-  //error message and return false.
-
-  error.SetErrorStringWithFormat(
-  "Target supports (%u) hardware watchpoint slots.\n",
-  *num_supported_hardware_watchpoints);
-  return false;
-  
+  if (*num_supported_hardware_watchpoints == 0) {
+error.SetErrorStringWithFormat(
+"Target supports (%u) hardware watchpoint slots.\n",
+*num_supported_hardware_watchpoints);
+return false;
+  }
   return true;
 }
 

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-13 Thread via lldb-commits

https://github.com/aabhinavg updated 
https://github.com/llvm/llvm-project/pull/91882

>From 9b4160975efe059f39a842689b1f750a10453203 Mon Sep 17 00:00:00 2001
From: aabhinavg 
Date: Sun, 12 May 2024 12:42:59 +0530
Subject: [PATCH] Fix redundant condition in Target.cpp

This commit addresses issue #87244, where a redundant condition was found in 
the Target.cpp file.
Static analyzer cppcheck flagged the issue in the Target.cpp file
---
 lldb/source/Target/Target.cpp | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 82f3040e539a3..fe87728a33dc8 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  if (num_supported_hardware_watchpoints == 0) {
-error.SetErrorStringWithFormat(
-"Target supports (%u) hardware watchpoint slots.\n",
-*num_supported_hardware_watchpoints);
-return false;
-  }
+  // If num_supported_hardware_watchpoints is zero, set an 
+  //error message and return false.
+
+  error.SetErrorStringWithFormat(
+  "Target supports (%u) hardware watchpoint slots.\n",
+  *num_supported_hardware_watchpoints);
+  return false;
+  
   return true;
 }
 

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-13 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett requested changes to this pull request.

I think this function got a bit confused when we changed the return type to an 
optional, thanks for taking a look at it.

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-13 Thread David Spickett via lldb-commits


@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  if (num_supported_hardware_watchpoints == 0) {
-error.SetErrorStringWithFormat(
-"Target supports (%u) hardware watchpoint slots.\n",
-*num_supported_hardware_watchpoints);
-return false;
-  }
+  // If num_supported_hardware_watchpoints is zero, set an 
+  //error message and return false.

DavidSpickett wrote:

I think this function can go one of three ways:
* We can't detect h/w watch, so we assume they are supported.
* We can detect them and there are > 0, return true.
* We can detect them but there are 0 of them, set error message and return 
false.

The code as you've got it here will set the error message if either of the 
final 2 are true.

What you could do to keep the intended behaviour is simply change the if to:
```
if (*num_supported_hardware_watchpoints == 0)
```
Then there is no redundant conditon, the first if checks whether the optional 
is valid, the second one checks the value contained in it.

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-13 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-12 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 63224d717108d927e998da8a67050a6cc5dd74a2 
9b4160975efe059f39a842689b1f750a10453203 -- lldb/source/Target/Target.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index fe87728a33..afc9506d3d 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,14 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  // If num_supported_hardware_watchpoints is zero, set an 
-  //error message and return false.
+  // If num_supported_hardware_watchpoints is zero, set an
+  // error message and return false.
 
   error.SetErrorStringWithFormat(
   "Target supports (%u) hardware watchpoint slots.\n",
   *num_supported_hardware_watchpoints);
   return false;
-  
+
   return true;
 }
 

``




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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-12 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (aabhinavg)


Changes

This commit addresses issue #87244, where a redundant condition was 
found in the Target.cpp file. Static analyzer cppcheck flagged the issue in the 
Target.cpp file
fix #87244 

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


1 Files Affected:

- (modified) lldb/source/Target/Target.cpp (+8-6) 


``diff
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 82f3040e539a3..fe87728a33dc8 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  if (num_supported_hardware_watchpoints == 0) {
-error.SetErrorStringWithFormat(
-"Target supports (%u) hardware watchpoint slots.\n",
-*num_supported_hardware_watchpoints);
-return false;
-  }
+  // If num_supported_hardware_watchpoints is zero, set an 
+  //error message and return false.
+
+  error.SetErrorStringWithFormat(
+  "Target supports (%u) hardware watchpoint slots.\n",
+  *num_supported_hardware_watchpoints);
+  return false;
+  
   return true;
 }
 

``




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


[Lldb-commits] [lldb] [lldb] Fix redundant condition in Target.cpp (PR #91882)

2024-05-12 Thread via lldb-commits

https://github.com/aabhinavg created 
https://github.com/llvm/llvm-project/pull/91882

This commit addresses issue #87244, where a redundant condition was found in 
the Target.cpp file. Static analyzer cppcheck flagged the issue in the 
Target.cpp file
fix #87244 

>From 9b4160975efe059f39a842689b1f750a10453203 Mon Sep 17 00:00:00 2001
From: aabhinavg 
Date: Sun, 12 May 2024 12:42:59 +0530
Subject: [PATCH] Fix redundant condition in Target.cpp

This commit addresses issue #87244, where a redundant condition was found in 
the Target.cpp file.
Static analyzer cppcheck flagged the issue in the Target.cpp file
---
 lldb/source/Target/Target.cpp | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 82f3040e539a3..fe87728a33dc8 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, 
Status ) {
   if (!num_supported_hardware_watchpoints)
 return true;
 
-  if (num_supported_hardware_watchpoints == 0) {
-error.SetErrorStringWithFormat(
-"Target supports (%u) hardware watchpoint slots.\n",
-*num_supported_hardware_watchpoints);
-return false;
-  }
+  // If num_supported_hardware_watchpoints is zero, set an 
+  //error message and return false.
+
+  error.SetErrorStringWithFormat(
+  "Target supports (%u) hardware watchpoint slots.\n",
+  *num_supported_hardware_watchpoints);
+  return false;
+  
   return true;
 }
 

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