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

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Mon May 13 01:21:03 PDT 2024


================
@@ -841,12 +841,14 @@ static bool CheckIfWatchpointsSupported(Target *target, Status &error) {
   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


More information about the lldb-commits mailing list