Skip to content

Commit ab0fa6c

Browse files
committed
[lldb] Fix else-after-return in Breakpoint (NFC)
The LLVM Coding Standards [1] discourages the use of 'else' or 'else if' after something that interrupts control flow. Bulk fix all instances as I'm working on this part of LLDB. [1] https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
1 parent a63f572 commit ab0fa6c

File tree

9 files changed

+36
-55
lines changed

9 files changed

+36
-55
lines changed

lldb/include/lldb/Breakpoint/BreakpointResolver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ class BreakpointResolver : public Searcher {
148148
enum ResolverTy GetResolverTy() {
149149
if (SubclassID > ResolverTy::LastKnownResolverType)
150150
return ResolverTy::UnknownResolver;
151-
else
152-
return (enum ResolverTy)SubclassID;
151+
return (enum ResolverTy)SubclassID;
153152
}
154153

155154
const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ void Breakpoint::SetThreadID(lldb::tid_t thread_id) {
347347
lldb::tid_t Breakpoint::GetThreadID() const {
348348
if (m_options.GetThreadSpecNoCreate() == nullptr)
349349
return LLDB_INVALID_THREAD_ID;
350-
else
351-
return m_options.GetThreadSpecNoCreate()->GetTID();
350+
return m_options.GetThreadSpecNoCreate()->GetTID();
352351
}
353352

354353
void Breakpoint::SetThreadIndex(uint32_t index) {
@@ -362,8 +361,7 @@ void Breakpoint::SetThreadIndex(uint32_t index) {
362361
uint32_t Breakpoint::GetThreadIndex() const {
363362
if (m_options.GetThreadSpecNoCreate() == nullptr)
364363
return 0;
365-
else
366-
return m_options.GetThreadSpecNoCreate()->GetIndex();
364+
return m_options.GetThreadSpecNoCreate()->GetIndex();
367365
}
368366

369367
void Breakpoint::SetThreadName(const char *thread_name) {
@@ -378,8 +376,7 @@ void Breakpoint::SetThreadName(const char *thread_name) {
378376
const char *Breakpoint::GetThreadName() const {
379377
if (m_options.GetThreadSpecNoCreate() == nullptr)
380378
return nullptr;
381-
else
382-
return m_options.GetThreadSpecNoCreate()->GetName();
379+
return m_options.GetThreadSpecNoCreate()->GetName();
383380
}
384381

385382
void Breakpoint::SetQueueName(const char *queue_name) {
@@ -394,8 +391,7 @@ void Breakpoint::SetQueueName(const char *queue_name) {
394391
const char *Breakpoint::GetQueueName() const {
395392
if (m_options.GetThreadSpecNoCreate() == nullptr)
396393
return nullptr;
397-
else
398-
return m_options.GetThreadSpecNoCreate()->GetQueueName();
394+
return m_options.GetThreadSpecNoCreate()->GetQueueName();
399395
}
400396

401397
void Breakpoint::SetCondition(const char *condition) {
@@ -851,8 +847,8 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
851847
if (level == eDescriptionLevelBrief) {
852848
s->PutCString(GetBreakpointKind());
853849
return;
854-
} else
855-
s->Printf("Kind: %s\n", GetBreakpointKind());
850+
}
851+
s->Printf("Kind: %s\n", GetBreakpointKind());
856852
}
857853

858854
const size_t num_locations = GetNumLocations();
@@ -1085,8 +1081,7 @@ Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
10851081

10861082
if (data == nullptr)
10871083
return eBreakpointEventTypeInvalidType;
1088-
else
1089-
return data->GetBreakpointEventType();
1084+
return data->GetBreakpointEventType();
10901085
}
10911086

10921087
BreakpointSP Breakpoint::BreakpointEventData::GetBreakpointFromEvent(

lldb/source/Breakpoint/BreakpointIDList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ llvm::Error BreakpointIDList::FindAndReplaceIDRanges(
9999
new_args.Clear();
100100
return llvm::createStringError(llvm::inconvertibleErrorCode(),
101101
error.AsCString());
102-
} else
103-
names_found.insert(std::string(current_arg));
102+
}
103+
names_found.insert(std::string(current_arg));
104104
} else if ((i + 2 < old_args.size()) &&
105105
BreakpointID::IsRangeIdentifier(old_args[i + 1].ref()) &&
106106
BreakpointID::IsValidIDExpression(current_arg) &&

lldb/source/Breakpoint/BreakpointLocation.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ const BreakpointOptions &BreakpointLocation::GetOptionsSpecifyingKind(
5555
BreakpointOptions::OptionKind kind) const {
5656
if (m_options_up && m_options_up->IsOptionSet(kind))
5757
return *m_options_up;
58-
else
59-
return m_owner.GetOptions();
58+
return m_owner.GetOptions();
6059
}
6160

6261
Address &BreakpointLocation::GetAddress() { return m_address; }
@@ -68,10 +67,9 @@ Target &BreakpointLocation::GetTarget() { return m_owner.GetTarget(); }
6867
bool BreakpointLocation::IsEnabled() const {
6968
if (!m_owner.IsEnabled())
7069
return false;
71-
else if (m_options_up != nullptr)
70+
if (m_options_up != nullptr)
7271
return m_options_up->IsEnabled();
73-
else
74-
return true;
72+
return true;
7573
}
7674

7775
void BreakpointLocation::SetEnabled(bool enabled) {
@@ -89,8 +87,7 @@ bool BreakpointLocation::IsAutoContinue() const {
8987
if (m_options_up &&
9088
m_options_up->IsOptionSet(BreakpointOptions::eAutoContinue))
9189
return m_options_up->IsAutoContinue();
92-
else
93-
return m_owner.IsAutoContinue();
90+
return m_owner.IsAutoContinue();
9491
}
9592

9693
void BreakpointLocation::SetAutoContinue(bool auto_continue) {
@@ -109,8 +106,7 @@ lldb::tid_t BreakpointLocation::GetThreadID() {
109106
.GetThreadSpecNoCreate();
110107
if (thread_spec)
111108
return thread_spec->GetTID();
112-
else
113-
return LLDB_INVALID_THREAD_ID;
109+
return LLDB_INVALID_THREAD_ID;
114110
}
115111

116112
void BreakpointLocation::SetThreadIndex(uint32_t index) {
@@ -131,8 +127,7 @@ uint32_t BreakpointLocation::GetThreadIndex() const {
131127
.GetThreadSpecNoCreate();
132128
if (thread_spec)
133129
return thread_spec->GetIndex();
134-
else
135-
return 0;
130+
return 0;
136131
}
137132

138133
void BreakpointLocation::SetThreadName(const char *thread_name) {
@@ -153,8 +148,7 @@ const char *BreakpointLocation::GetThreadName() const {
153148
.GetThreadSpecNoCreate();
154149
if (thread_spec)
155150
return thread_spec->GetName();
156-
else
157-
return nullptr;
151+
return nullptr;
158152
}
159153

160154
void BreakpointLocation::SetQueueName(const char *queue_name) {
@@ -175,22 +169,19 @@ const char *BreakpointLocation::GetQueueName() const {
175169
.GetThreadSpecNoCreate();
176170
if (thread_spec)
177171
return thread_spec->GetQueueName();
178-
else
179-
return nullptr;
172+
return nullptr;
180173
}
181174

182175
bool BreakpointLocation::InvokeCallback(StoppointCallbackContext *context) {
183176
if (m_options_up != nullptr && m_options_up->HasCallback())
184177
return m_options_up->InvokeCallback(context, m_owner.GetID(), GetID());
185-
else
186-
return m_owner.InvokeCallback(context, GetID());
178+
return m_owner.InvokeCallback(context, GetID());
187179
}
188180

189181
bool BreakpointLocation::IsCallbackSynchronous() {
190182
if (m_options_up != nullptr && m_options_up->HasCallback())
191183
return m_options_up->IsCallbackSynchronous();
192-
else
193-
return m_owner.GetOptions().IsCallbackSynchronous();
184+
return m_owner.GetOptions().IsCallbackSynchronous();
194185
}
195186

196187
void BreakpointLocation::SetCallback(BreakpointHitCallback callback,

lldb/source/Breakpoint/BreakpointLocationList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ BreakpointLocationList::FindByID(lldb::break_id_t break_id) const {
7272
llvm::lower_bound(m_locations, break_id, Compare);
7373
if (pos != end && (*pos)->GetID() == break_id)
7474
return *(pos);
75-
else
76-
return BreakpointLocationSP();
75+
return BreakpointLocationSP();
7776
}
7877

7978
size_t BreakpointLocationList::FindInModule(

lldb/source/Breakpoint/BreakpointOptions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ bool BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
438438
return m_callback(m_callback_baton_sp ? m_callback_baton_sp->data()
439439
: nullptr,
440440
context, break_id, break_loc_id);
441-
} else if (IsCallbackSynchronous()) {
441+
}
442+
if (IsCallbackSynchronous()) {
442443
return false;
443444
}
444445
}
@@ -482,9 +483,8 @@ const char *BreakpointOptions::GetConditionText(size_t *hash) const {
482483
*hash = m_condition_text_hash;
483484

484485
return m_condition_text.c_str();
485-
} else {
486-
return nullptr;
487486
}
487+
return nullptr;
488488
}
489489

490490
const ThreadSpec *BreakpointOptions::GetThreadSpecNoCreate() const {

lldb/source/Breakpoint/BreakpointResolverName.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ BreakpointResolverSP BreakpointResolverName::CreateFromStructuredData(
124124
return std::make_shared<BreakpointResolverName>(
125125
nullptr, RegularExpression(regex_text), language, offset,
126126
skip_prologue);
127-
} else {
128-
StructuredData::Array *names_array;
129-
success = options_dict.GetValueForKeyAsArray(
130-
GetKey(OptionNames::SymbolNameArray), names_array);
131-
if (!success) {
132-
error = Status::FromErrorString("BRN::CFSD: Missing symbol names entry.");
133-
return nullptr;
134-
}
127+
}
128+
StructuredData::Array *names_array;
129+
success = options_dict.GetValueForKeyAsArray(
130+
GetKey(OptionNames::SymbolNameArray), names_array);
131+
if (!success) {
132+
error = Status::FromErrorString("BRN::CFSD: Missing symbol names entry.");
133+
return nullptr;
134+
}
135135
StructuredData::Array *names_mask_array;
136136
success = options_dict.GetValueForKeyAsArray(
137137
GetKey(OptionNames::NameMaskArray), names_mask_array);
@@ -182,7 +182,6 @@ BreakpointResolverSP BreakpointResolverName::CreateFromStructuredData(
182182
resolver_sp->AddNameLookup(ConstString(names[i]), name_masks[i]);
183183
}
184184
return resolver_sp;
185-
}
186185
}
187186

188187
StructuredData::ObjectSP BreakpointResolverName::SerializeToStructuredData() {

lldb/source/Breakpoint/Watchpoint.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ void Watchpoint::SetCondition(const char *condition) {
477477
const char *Watchpoint::GetConditionText() const {
478478
if (m_condition_up)
479479
return m_condition_up->GetUserText();
480-
else
481-
return nullptr;
480+
return nullptr;
482481
}
483482

484483
void Watchpoint::SendWatchpointChangedEvent(
@@ -534,8 +533,7 @@ Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
534533

535534
if (data == nullptr)
536535
return eWatchpointEventTypeInvalidType;
537-
else
538-
return data->GetWatchpointEventType();
536+
return data->GetWatchpointEventType();
539537
}
540538

541539
WatchpointSP Watchpoint::WatchpointEventData::GetWatchpointFromEvent(

lldb/source/Breakpoint/WatchpointOptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ bool WatchpointOptions::InvokeCallback(StoppointCallbackContext *context,
9292
return m_callback(m_callback_baton_sp ? m_callback_baton_sp->data()
9393
: nullptr,
9494
context, watch_id);
95-
} else
96-
return true;
95+
}
96+
return true;
9797
}
9898

9999
bool WatchpointOptions::HasCallback() {

0 commit comments

Comments
 (0)