[Lldb-commits] [lldb] d24d7ed - [lldb][NFC] Delete unreachable code and dead variable in OptionArgParser

Felipe de Azevedo Piovezan via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 4 10:25:01 PST 2023


Author: Felipe de Azevedo Piovezan
Date: 2023-12-04T10:23:05-08:00
New Revision: d24d7edaef9517edd9eb2ab26b02969e201bbcad

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

LOG: [lldb][NFC] Delete unreachable code and dead variable in OptionArgParser

With the combination of an early return and removing an else-after-return, it
becomes evident that there is unreachable code in the function being changed.

Added: 
    

Modified: 
    lldb/source/Interpreter/OptionArgParser.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index c61072dfafc19..8a92c7d08c476 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -211,7 +211,6 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
       target->EvaluateExpression(s, exe_ctx->GetFramePtr(), valobj_sp, options);
 
   bool success = false;
-  bool error_set = false;
   if (expr_result == eExpressionCompleted) {
     if (valobj_sp)
       valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
@@ -224,48 +223,39 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
         error_ptr->Clear();
       return addr;
     }
-    if (error_ptr) {
-      error_set = true;
+    if (error_ptr)
       error_ptr->SetErrorStringWithFormat(
           "address expression \"%s\" resulted in a value whose type "
           "can't be converted to an address: %s",
           s.str().c_str(), valobj_sp->GetTypeName().GetCString());
-    }
-  } else {
-    // Since the compiler can't handle things like "main + 12" we should try to
-    // do this for now. The compiler doesn't like adding offsets to function
-    // pointer types.
-    static RegularExpression g_symbol_plus_offset_regex(
-        "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
-
-    llvm::SmallVector<llvm::StringRef, 4> matches;
-    if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
-      uint64_t offset = 0;
-      llvm::StringRef name = matches[1];
-      llvm::StringRef sign = matches[2];
-      llvm::StringRef str_offset = matches[3];
-      if (!str_offset.getAsInteger(0, offset)) {
-        Status error;
-        addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
-        if (addr != LLDB_INVALID_ADDRESS) {
-          if (sign[0] == '+')
-            return addr + offset;
-          return addr - offset;
-        }
-      }
-    }
+    return {};
+  }
 
-    if (error_ptr) {
-      error_set = true;
-      error_ptr->SetErrorStringWithFormat(
-          "address expression \"%s\" evaluation failed", s.str().c_str());
+  // Since the compiler can't handle things like "main + 12" we should try to
+  // do this for now. The compiler doesn't like adding offsets to function
+  // pointer types.
+  static RegularExpression g_symbol_plus_offset_regex(
+      "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+
+  llvm::SmallVector<llvm::StringRef, 4> matches;
+  if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
+    uint64_t offset = 0;
+    llvm::StringRef name = matches[1];
+    llvm::StringRef sign = matches[2];
+    llvm::StringRef str_offset = matches[3];
+    if (!str_offset.getAsInteger(0, offset)) {
+      Status error;
+      addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
+      if (addr != LLDB_INVALID_ADDRESS) {
+        if (sign[0] == '+')
+          return addr + offset;
+        return addr - offset;
+      }
     }
   }
 
-  if (error_ptr) {
-    if (!error_set)
-      error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
-                                          s.str().c_str());
-  }
+  if (error_ptr)
+    error_ptr->SetErrorStringWithFormat(
+        "address expression \"%s\" evaluation failed", s.str().c_str());
   return {};
 }


        


More information about the lldb-commits mailing list