aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>2023-12-01 09:47:57 -0800
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>2023-12-04 10:23:05 -0800
commitd24d7edaef9517edd9eb2ab26b02969e201bbcad (patch)
tree45f4d8fa63b2ad3a244ec350467e184fd1efa33b
parent3e98a285138a517fd918ec0ac8397dc56330d8e7 (diff)
downloadllvm-d24d7edaef9517edd9eb2ab26b02969e201bbcad.zip
llvm-d24d7edaef9517edd9eb2ab26b02969e201bbcad.tar.gz
llvm-d24d7edaef9517edd9eb2ab26b02969e201bbcad.tar.bz2
[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.
-rw-r--r--lldb/source/Interpreter/OptionArgParser.cpp62
1 files changed, 26 insertions, 36 deletions
diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index c61072d..8a92c7d 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 {};
}