Skip to content

Commit d24d7ed

Browse files
[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.
1 parent 3e98a28 commit d24d7ed

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

lldb/source/Interpreter/OptionArgParser.cpp

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
211211
target->EvaluateExpression(s, exe_ctx->GetFramePtr(), valobj_sp, options);
212212

213213
bool success = false;
214-
bool error_set = false;
215214
if (expr_result == eExpressionCompleted) {
216215
if (valobj_sp)
217216
valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
@@ -224,48 +223,39 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
224223
error_ptr->Clear();
225224
return addr;
226225
}
227-
if (error_ptr) {
228-
error_set = true;
226+
if (error_ptr)
229227
error_ptr->SetErrorStringWithFormat(
230228
"address expression \"%s\" resulted in a value whose type "
231229
"can't be converted to an address: %s",
232230
s.str().c_str(), valobj_sp->GetTypeName().GetCString());
233-
}
234-
} else {
235-
// Since the compiler can't handle things like "main + 12" we should try to
236-
// do this for now. The compiler doesn't like adding offsets to function
237-
// pointer types.
238-
static RegularExpression g_symbol_plus_offset_regex(
239-
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
240-
241-
llvm::SmallVector<llvm::StringRef, 4> matches;
242-
if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
243-
uint64_t offset = 0;
244-
llvm::StringRef name = matches[1];
245-
llvm::StringRef sign = matches[2];
246-
llvm::StringRef str_offset = matches[3];
247-
if (!str_offset.getAsInteger(0, offset)) {
248-
Status error;
249-
addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
250-
if (addr != LLDB_INVALID_ADDRESS) {
251-
if (sign[0] == '+')
252-
return addr + offset;
253-
return addr - offset;
254-
}
255-
}
256-
}
231+
return {};
232+
}
257233

258-
if (error_ptr) {
259-
error_set = true;
260-
error_ptr->SetErrorStringWithFormat(
261-
"address expression \"%s\" evaluation failed", s.str().c_str());
234+
// Since the compiler can't handle things like "main + 12" we should try to
235+
// do this for now. The compiler doesn't like adding offsets to function
236+
// pointer types.
237+
static RegularExpression g_symbol_plus_offset_regex(
238+
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
239+
240+
llvm::SmallVector<llvm::StringRef, 4> matches;
241+
if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
242+
uint64_t offset = 0;
243+
llvm::StringRef name = matches[1];
244+
llvm::StringRef sign = matches[2];
245+
llvm::StringRef str_offset = matches[3];
246+
if (!str_offset.getAsInteger(0, offset)) {
247+
Status error;
248+
addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
249+
if (addr != LLDB_INVALID_ADDRESS) {
250+
if (sign[0] == '+')
251+
return addr + offset;
252+
return addr - offset;
253+
}
262254
}
263255
}
264256

265-
if (error_ptr) {
266-
if (!error_set)
267-
error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
268-
s.str().c_str());
269-
}
257+
if (error_ptr)
258+
error_ptr->SetErrorStringWithFormat(
259+
"address expression \"%s\" evaluation failed", s.str().c_str());
270260
return {};
271261
}

0 commit comments

Comments
 (0)