Skip to content

Commit 05d4535

Browse files
committed
clang-tidy: Add readability-else-after-return
1 parent 9df487e commit 05d4535

22 files changed

+484
-463
lines changed

.clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Checks: -*,modernize-*,-modernize-redundant-void-arg,google-readability-braces-around-statements,google-explicit-constructor,google-readability-casting,misc-assert-side-effect,misc-assign-operator-signature,misc-inefficient-algorithm,misc-move-constructor-init,misc-non-copyable-objects,misc-sizeof-container,misc-undelegated-constructor,misc-unused-alias-decls,readability-container-size-empty,readability-redundant-string-cstr
1+
Checks: -*,modernize-*,-modernize-redundant-void-arg,google-readability-braces-around-statements,google-explicit-constructor,google-readability-casting,misc-assert-side-effect,misc-assign-operator-signature,misc-inefficient-algorithm,misc-move-constructor-init,misc-non-copyable-objects,misc-sizeof-container,misc-undelegated-constructor,misc-unused-alias-decls,readability-container-size-empty,readability-else-after-return,readability-redundant-string-cstr

gen/abi-win64.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ bool Win64TargetABI::returnInArg(TypeFunction *tf) {
9898
// (incl. 2x32-bit cfloat) are returned in a register (RAX, or
9999
// XMM0 for single float/ifloat/double/idouble)
100100
// * all other types are returned via struct-return (sret)
101-
return (rt->ty == Tstruct && !((TypeStruct *)rt)->sym->isPOD()) ||
101+
return (rt->ty == Tstruct &&
102+
!(static_cast<TypeStruct *>(rt))->sym->isPOD()) ||
102103
isPassedWithByvalSemantics(rt);
103104
}
104105

gen/abi-x86.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,15 @@ struct X86TargetABI : TargetABI {
105105
}
106106
// other ABI's follow C, which is cdouble and creal returned on the stack
107107
// as well as structs (except for some OSX cases).
108-
else {
109-
if (isMagicCLong(rt)) {
110-
return false;
111-
}
112108

113-
if (rt->ty == Tstruct) {
114-
return !isOSX || returnOSXStructInArg((TypeStruct *)rt);
115-
}
116-
return (rt->ty == Tsarray || rt->ty == Tcomplex64 ||
117-
rt->ty == Tcomplex80);
109+
if (isMagicCLong(rt)) {
110+
return false;
111+
}
112+
113+
if (rt->ty == Tstruct) {
114+
return !isOSX || returnOSXStructInArg((TypeStruct *)rt);
118115
}
116+
return (rt->ty == Tsarray || rt->ty == Tcomplex64 || rt->ty == Tcomplex80);
119117
}
120118

121119
bool passByVal(Type *t) override {

gen/arrays.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,16 @@ LLValue *DtoArrayLen(DValue *v) {
10211021
if (t->ty == Tarray) {
10221022
if (DSliceValue *s = v->isSlice()) {
10231023
return s->len;
1024-
} else if (v->isNull()) {
1024+
}
1025+
if (v->isNull()) {
10251026
return DtoConstSize_t(0);
1026-
} else if (v->isLVal()) {
1027+
}
1028+
if (v->isLVal()) {
10271029
return DtoLoad(DtoGEPi(v->getLVal(), 0, 0), ".len");
10281030
}
10291031
return gIR->ir->CreateExtractValue(v->getRVal(), 0, ".len");
1030-
} else if (t->ty == Tsarray) {
1032+
}
1033+
if (t->ty == Tsarray) {
10311034
assert(!v->isSlice());
10321035
assert(!v->isNull());
10331036
assert(v->type->toBasetype()->ty == Tsarray);

gen/asm-x86.h

+15-14
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,14 @@ typedef struct {
531531
unsigned nOperands() {
532532
if (!operands[0]) {
533533
return 0;
534-
} else if (!operands[1]) {
534+
}
535+
if (!operands[1]) {
535536
return 1;
536-
} else if (!operands[2]) {
537+
}
538+
if (!operands[2]) {
537539
return 2;
538-
} else {
539-
return 3;
540540
}
541+
return 3;
541542
}
542543
} AsmOpInfo;
543544

@@ -2085,9 +2086,8 @@ struct AsmProcessor {
20852086
Token *peekToken() {
20862087
if (token->next) {
20872088
return token->next;
2088-
} else {
2089-
return &eof_tok;
20902089
}
2090+
return &eof_tok;
20912091
}
20922092

20932093
void expectEnd() {
@@ -2162,7 +2162,8 @@ struct AsmProcessor {
21622162
l = strcmp(opcode, opData[k].inMnemonic);
21632163
if (!l) {
21642164
return opData[k].asmOp;
2165-
} else if (l < 0) {
2165+
}
2166+
if (l < 0) {
21662167
j = k;
21672168
} else {
21682169
i = k + 1;
@@ -3282,10 +3283,9 @@ struct AsmProcessor {
32823283
}
32833284
e = e->semantic(sc);
32843285
return e->ctfeInterpret();
3285-
} else {
3286-
stmt->error("expected integer operand(s) for '%s'", Token::tochars[op]);
3287-
return newIntExp(0);
32883286
}
3287+
stmt->error("expected integer operand(s) for '%s'", Token::tochars[op]);
3288+
return newIntExp(0);
32893289
}
32903290

32913291
void parseOperand() {
@@ -3717,7 +3717,8 @@ struct AsmProcessor {
37173717

37183718
if (ident == Id::__LOCAL_SIZE) {
37193719
return new IdentifierExp(stmt->loc, ident);
3720-
} else if (ident == Id::dollar) {
3720+
}
3721+
if (ident == Id::dollar) {
37213722
do_dollar:
37223723
return new IdentifierExp(stmt->loc, ident);
37233724
} else {
@@ -3772,7 +3773,8 @@ struct AsmProcessor {
37723773
}
37733774
invalidExpression();
37743775
return Handled;
3775-
} else if (token->value == TOKcolon) {
3776+
}
3777+
if (token->value == TOKcolon) {
37763778
nextToken();
37773779
if (operand->segmentPrefix != Reg_Invalid) {
37783780
stmt->error("too many segment prefixes");
@@ -3782,9 +3784,8 @@ struct AsmProcessor {
37823784
stmt->error("'%s' is not a segment register", ident->string);
37833785
}
37843786
return parseAsmExp();
3785-
} else {
3786-
return newRegExp(static_cast<Reg>(i));
37873787
}
3788+
return newRegExp(static_cast<Reg>(i));
37883789
}
37893790
}
37903791
}

gen/cl_helpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ template <class DataType> class FlagParser : public cl::generic_parser_base {
9999

100100
private:
101101
struct OptionValue : cl::OptionValueBase<DataType, false> {
102-
OptionValue() {}
102+
OptionValue(){};
103103
};
104104
const OptionValue EmptyOptionValue;
105105

gen/classes.cpp

+24-27
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
209209
return new DImValue(_to, rval);
210210
}
211211
// class -> bool
212-
else if (to->ty == Tbool) {
212+
if (to->ty == Tbool) {
213213
IF_LOG Logger::println("to bool");
214214
LLValue *llval = val->getRVal();
215215
LLValue *zero = LLConstant::getNullValue(llval->getType());
216216
return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero));
217217
}
218218
// class -> integer
219-
else if (to->isintegral()) {
219+
if (to->isintegral()) {
220220
IF_LOG Logger::println("to %s", to->toChars());
221221

222222
// get class ptr
@@ -228,7 +228,7 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
228228
return DtoCastInt(loc, &im, _to);
229229
}
230230
// class -> typeof(null)
231-
else if (to->ty == Tnull) {
231+
if (to->ty == Tnull) {
232232
IF_LOG Logger::println("to %s", to->toChars());
233233
return new DImValue(_to, LLConstant::getNullValue(DtoType(_to)));
234234
}
@@ -256,7 +256,7 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
256256
return DtoDynamicCastInterface(loc, val, _to);
257257
}
258258
// class -> interface - static cast
259-
else if (it->isBaseOf(fc->sym, nullptr)) {
259+
if (it->isBaseOf(fc->sym, nullptr)) {
260260
Logger::println("static down cast");
261261

262262
// get the from class
@@ -295,32 +295,29 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
295295
return new DImValue(_to, v);
296296
}
297297
// class -> interface
298-
else {
299-
Logger::println("from object");
300-
return DtoDynamicCastObject(loc, val, _to);
301-
}
298+
299+
Logger::println("from object");
300+
return DtoDynamicCastObject(loc, val, _to);
302301
}
303302
// x -> class
304-
else {
305-
Logger::println("to class");
306-
// interface -> class
307-
if (fc->sym->isInterfaceDeclaration()) {
308-
Logger::println("interface cast");
309-
return DtoDynamicCastInterface(loc, val, _to);
310-
}
311-
// class -> class - static down cast
312-
else if (tc->sym->isBaseOf(fc->sym, nullptr)) {
313-
Logger::println("static down cast");
314-
LLType *tolltype = DtoType(_to);
315-
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
316-
return new DImValue(_to, rval);
317-
}
318-
// class -> class - dynamic up cast
319-
else {
320-
Logger::println("dynamic up cast");
321-
return DtoDynamicCastObject(loc, val, _to);
322-
}
303+
304+
Logger::println("to class");
305+
// interface -> class
306+
if (fc->sym->isInterfaceDeclaration()) {
307+
Logger::println("interface cast");
308+
return DtoDynamicCastInterface(loc, val, _to);
323309
}
310+
// class -> class - static down cast
311+
if (tc->sym->isBaseOf(fc->sym, nullptr)) {
312+
Logger::println("static down cast");
313+
LLType *tolltype = DtoType(_to);
314+
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
315+
return new DImValue(_to, rval);
316+
}
317+
// class -> class - dynamic up cast
318+
319+
Logger::println("dynamic up cast");
320+
return DtoDynamicCastObject(loc, val, _to);
324321
}
325322

326323
//////////////////////////////////////////////////////////////////////////////////////////

gen/complex.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ LLValue *DtoComplexEquals(Loc &loc, TOK op, DValue *lhs, DValue *rhs) {
423423

424424
if (op == TOKequal) {
425425
return gIR->ir->CreateAnd(b1, b2);
426-
} else {
427-
return gIR->ir->CreateOr(b1, b2);
428426
}
427+
return gIR->ir->CreateOr(b1, b2);
429428
}
430429

431430
//////////////////////////////////////////////////////////////////////////////////////////
@@ -452,7 +451,8 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {
452451

453452
LLValue *pair = DtoAggrPair(DtoType(_to), re, im);
454453
return new DImValue(_to, pair);
455-
} else if (to->isimaginary()) {
454+
}
455+
if (to->isimaginary()) {
456456
// FIXME: this loads both values, even when we only need one
457457
LLValue *v = val->getRVal();
458458
LLValue *impart = gIR->ir->CreateExtractValue(v, 1, ".im_part");
@@ -472,10 +472,12 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {
472472
}
473473
auto im = new DImValue(extractty, impart);
474474
return DtoCastFloat(loc, im, to);
475-
} else if (to->ty == Tbool) {
475+
}
476+
if (to->ty == Tbool) {
476477
return new DImValue(
477478
_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty)));
478-
} else if (to->isfloating() || to->isintegral()) {
479+
}
480+
if (to->isfloating() || to->isintegral()) {
479481
// FIXME: this loads both values, even when we only need one
480482
LLValue *v = val->getRVal();
481483
LLValue *repart = gIR->ir->CreateExtractValue(v, 0, ".re_part");
@@ -495,9 +497,7 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {
495497
}
496498
auto re = new DImValue(extractty, repart);
497499
return DtoCastFloat(loc, re, to);
498-
} else {
499-
error(loc, "Don't know how to cast %s to %s", vty->toChars(),
500-
to->toChars());
501-
fatal();
502500
}
501+
error(loc, "Don't know how to cast %s to %s", vty->toChars(), to->toChars());
502+
fatal();
503503
}

0 commit comments

Comments
 (0)