Skip to content

Commit 904de95

Browse files
authored
[clang][bytecode][NFC] Fix a few clang-tidy complaints (#150940)
1 parent 01d4b8e commit 904de95

File tree

8 files changed

+45
-44
lines changed

8 files changed

+45
-44
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,8 @@ bool Compiler<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
10221022
if (classifyPrim(E) != PT_Ptr)
10231023
return this->emitDecayPtr(PT_Ptr, classifyPrim(E), E);
10241024
return true;
1025-
} else if (Op == BO_Sub) {
1025+
}
1026+
if (Op == BO_Sub) {
10261027
if (!this->emitSubOffset(OffsetType, E))
10271028
return false;
10281029

@@ -3703,7 +3704,7 @@ bool Compiler<Emitter>::VisitBlockExpr(const BlockExpr *E) {
37033704
return true;
37043705

37053706
const Function *Func = nullptr;
3706-
if (auto F = Ctx.getOrCreateObjCBlock(E))
3707+
if (const Function *F = Ctx.getOrCreateObjCBlock(E))
37073708
Func = F;
37083709

37093710
if (!Func)
@@ -4288,7 +4289,8 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
42884289
return false;
42894290
}
42904291
return true;
4291-
} else if (ElemType->isRecordType()) {
4292+
}
4293+
if (ElemType->isRecordType()) {
42924294
const Record *R = getRecord(ElemType);
42934295

42944296
for (size_t I = 0; I != NumElems; ++I) {
@@ -4302,7 +4304,8 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
43024304
return false;
43034305
}
43044306
return true;
4305-
} else if (ElemType->isArrayType()) {
4307+
}
4308+
if (ElemType->isArrayType()) {
43064309
for (size_t I = 0; I != NumElems; ++I) {
43074310
if (!this->emitConstUint32(I, E))
43084311
return false;
@@ -4774,11 +4777,10 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
47744777
if (!this->visit(Init))
47754778
return false;
47764779
return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals();
4777-
} else {
4780+
}
47784781
if (!this->visit(Init))
47794782
return false;
47804783
return this->emitSetLocal(*VarT, Offset, VD);
4781-
}
47824784
}
47834785
} else {
47844786
if (std::optional<unsigned> Offset = this->allocateLocal(
@@ -4805,7 +4807,7 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
48054807
assert(!DiscardResult);
48064808
if (Val.isInt())
48074809
return this->emitConst(Val.getInt(), ValType, E);
4808-
else if (Val.isFloat()) {
4810+
if (Val.isFloat()) {
48094811
APFloat F = Val.getFloat();
48104812
return this->emitFloat(F, E);
48114813
}
@@ -4816,9 +4818,8 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
48164818
APValue::LValueBase Base = Val.getLValueBase();
48174819
if (const Expr *BaseExpr = Base.dyn_cast<const Expr *>())
48184820
return this->visit(BaseExpr);
4819-
else if (const auto *VD = Base.dyn_cast<const ValueDecl *>()) {
4821+
if (const auto *VD = Base.dyn_cast<const ValueDecl *>())
48204822
return this->visitDeclRef(VD, E);
4821-
}
48224823
} else if (Val.isMemberPointer()) {
48234824
if (const ValueDecl *MemberDecl = Val.getMemberPointerDecl())
48244825
return this->emitGetMemberPtr(MemberDecl, E);
@@ -4854,7 +4855,8 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
48544855
}
48554856
}
48564857
return true;
4857-
} else if (Val.isUnion()) {
4858+
}
4859+
if (Val.isUnion()) {
48584860
const FieldDecl *UnionField = Val.getUnionField();
48594861
const Record *R = this->getRecord(UnionField->getParent());
48604862
assert(R);
@@ -4864,7 +4866,8 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
48644866
if (!this->visitAPValue(F, T, E))
48654867
return false;
48664868
return this->emitInitField(T, RF->Offset, E);
4867-
} else if (Val.isArray()) {
4869+
}
4870+
if (Val.isArray()) {
48684871
const auto *ArrType = T->getAsArrayTypeUnsafe();
48694872
QualType ElemType = ArrType->getElementType();
48704873
for (unsigned A = 0, AN = Val.getArraySize(); A != AN; ++A) {
@@ -4981,12 +4984,10 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
49814984

49824985
// Calls to replaceable operator new/operator delete.
49834986
if (FuncDecl->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4984-
if (FuncDecl->getDeclName().isAnyOperatorNew()) {
4987+
if (FuncDecl->getDeclName().isAnyOperatorNew())
49854988
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_new);
4986-
} else {
4987-
assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);
4988-
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
4989-
}
4989+
assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);
4990+
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
49904991
}
49914992

49924993
// Explicit calls to trivial destructors
@@ -5455,7 +5456,9 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
54555456
return false;
54565457
this->emitCleanup();
54575458
return this->emitRet(*ReturnType, RS);
5458-
} else if (RE->getType()->isVoidType()) {
5459+
}
5460+
5461+
if (RE->getType()->isVoidType()) {
54595462
if (!this->visit(RE))
54605463
return false;
54615464
} else {
@@ -5500,7 +5503,7 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
55005503
if (std::optional<bool> BoolValue = getBoolValue(IS->getCond())) {
55015504
if (*BoolValue)
55025505
return visitChildStmt(IS->getThen());
5503-
else if (const Stmt *Else = IS->getElse())
5506+
if (const Stmt *Else = IS->getElse())
55045507
return visitChildStmt(Else);
55055508
return true;
55065509
}
@@ -5992,7 +5995,7 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
59925995
if (!this->emitThis(Ctor))
59935996
return false;
59945997

5995-
auto PVD = Ctor->getParamDecl(0);
5998+
const ParmVarDecl *PVD = Ctor->getParamDecl(0);
59965999
ParamOffset PO = this->Params[PVD]; // Must exist.
59976000

59986001
if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
@@ -6153,7 +6156,7 @@ bool Compiler<Emitter>::compileUnionAssignmentOperator(
61536156
if (!this->emitThis(MD))
61546157
return false;
61556158

6156-
auto PVD = MD->getParamDecl(0);
6159+
const ParmVarDecl *PVD = MD->getParamDecl(0);
61576160
ParamOffset PO = this->Params[PVD]; // Must exist.
61586161

61596162
if (!this->emitGetParam(PT_Ptr, PO.Offset, MD))

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
845845
return true;
846846
}
847847

848-
bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
848+
static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
849849

850850
if (F->isVirtual() && !S.getLangOpts().CPlusPlus20) {
851851
const SourceLocation &Loc = S.Current->getLocation(OpPC);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
240240
T CB = PB.deref<T>();
241241
if (CA > CB)
242242
return returnResult(1);
243-
else if (CA < CB)
243+
if (CA < CB)
244244
return returnResult(-1);
245-
else if (CA.isZero() || CB.isZero())
245+
if (CA.isZero() || CB.isZero())
246246
return returnResult(0);
247247
});
248248
continue;
@@ -253,7 +253,7 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
253253

254254
if (CA > CB)
255255
return returnResult(1);
256-
else if (CA < CB)
256+
if (CA < CB)
257257
return returnResult(-1);
258258
if (CA == 0 || CB == 0)
259259
return returnResult(0);
@@ -1048,7 +1048,7 @@ static bool interp__builtin_atomic_lock_free(InterpState &S, CodePtr OpPC,
10481048
PtrArg = ICE->getSubExpr();
10491049
}
10501050

1051-
if (auto PtrTy = PtrArg->getType()->getAs<PointerType>()) {
1051+
if (const auto *PtrTy = PtrArg->getType()->getAs<PointerType>()) {
10521052
QualType PointeeType = PtrTy->getPointeeType();
10531053
if (!PointeeType->isIncompleteType() &&
10541054
S.getASTContext().getTypeAlignInChars(PointeeType) >= Size) {
@@ -1967,7 +1967,8 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
19671967
if (A < B) {
19681968
pushInteger(S, -1, Call->getType());
19691969
return true;
1970-
} else if (A > B) {
1970+
}
1971+
if (A > B) {
19711972
pushInteger(S, 1, Call->getType());
19721973
return true;
19731974
}
@@ -1979,7 +1980,8 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
19791980
if (A < B) {
19801981
pushInteger(S, -1, Call->getType());
19811982
return true;
1982-
} else if (A > B) {
1983+
}
1984+
if (A > B) {
19831985
pushInteger(S, 1, Call->getType());
19841986
return true;
19851987
}

clang/lib/AST/ByteCode/InterpStack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
#define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
1515

1616
#include "FixedPoint.h"
17-
#include "FunctionPointer.h"
1817
#include "IntegralAP.h"
1918
#include "MemberPointer.h"
2019
#include "PrimType.h"
21-
#include <memory>
2220
#include <vector>
2321

2422
namespace clang {

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "MemberPointer.h"
1717
#include "PrimType.h"
1818
#include "Record.h"
19+
#include "clang/AST/Expr.h"
1920
#include "clang/AST/ExprCXX.h"
2021
#include "clang/AST/RecordLayout.h"
2122

@@ -66,14 +67,14 @@ Pointer::~Pointer() {
6667
}
6768
}
6869

69-
void Pointer::operator=(const Pointer &P) {
70+
Pointer &Pointer::operator=(const Pointer &P) {
7071
// If the current storage type is Block, we need to remove
7172
// this pointer from the block.
7273
if (isBlockPointer()) {
7374
if (P.isBlockPointer() && this->block() == P.block()) {
7475
Offset = P.Offset;
7576
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
76-
return;
77+
return *this;
7778
}
7879

7980
if (Block *Pointee = PointeeStorage.BS.Pointee) {
@@ -101,16 +102,17 @@ void Pointer::operator=(const Pointer &P) {
101102
} else {
102103
assert(false && "Unhandled storage kind");
103104
}
105+
return *this;
104106
}
105107

106-
void Pointer::operator=(Pointer &&P) {
108+
Pointer &Pointer::operator=(Pointer &&P) {
107109
// If the current storage type is Block, we need to remove
108110
// this pointer from the block.
109111
if (isBlockPointer()) {
110112
if (P.isBlockPointer() && this->block() == P.block()) {
111113
Offset = P.Offset;
112114
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
113-
return;
115+
return *this;
114116
}
115117

116118
if (Block *Pointee = PointeeStorage.BS.Pointee) {
@@ -138,6 +140,7 @@ void Pointer::operator=(Pointer &&P) {
138140
} else {
139141
assert(false && "Unhandled storage kind");
140142
}
143+
return *this;
141144
}
142145

143146
APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
@@ -603,7 +606,7 @@ bool Pointer::pointsToStringLiteral() const {
603606
return false;
604607

605608
const Expr *E = block()->getDescriptor()->asExpr();
606-
return E && isa<StringLiteral>(E);
609+
return isa_and_nonnull<StringLiteral>(E);
607610
}
608611

609612
std::optional<std::pair<Pointer, Pointer>>

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ class Pointer {
120120
Pointer(Block *Pointee, unsigned Base, uint64_t Offset);
121121
~Pointer();
122122

123-
void operator=(const Pointer &P);
124-
void operator=(Pointer &&P);
123+
Pointer &operator=(const Pointer &P);
124+
Pointer &operator=(Pointer &&P);
125125

126126
/// Equality operators are just for tests.
127127
bool operator==(const Pointer &P) const {
@@ -761,7 +761,7 @@ class Pointer {
761761

762762
if (Offset < Other.Offset)
763763
return ComparisonCategoryResult::Less;
764-
else if (Offset > Other.Offset)
764+
if (Offset > Other.Offset)
765765
return ComparisonCategoryResult::Greater;
766766

767767
return ComparisonCategoryResult::Equal;

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
418418
}
419419
return allocateDescriptor(D, *T, MDSize, NumElems, IsConst, IsTemporary,
420420
IsMutable);
421-
} else {
421+
}
422422
// Arrays of composites. In this case, the array is a list of pointers,
423423
// followed by the actual elements.
424424
const Descriptor *ElemDesc = createDescriptor(
@@ -430,7 +430,6 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
430430
return {};
431431
return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
432432
IsTemporary, IsMutable);
433-
}
434433
}
435434

436435
// Array of unknown bounds - cannot be accessed and pointer arithmetic
@@ -440,14 +439,13 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
440439
if (OptPrimType T = Ctx.classify(ElemTy)) {
441440
return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
442441
Descriptor::UnknownSize{});
443-
} else {
442+
}
444443
const Descriptor *Desc = createDescriptor(
445444
D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
446445
if (!Desc)
447446
return nullptr;
448447
return allocateDescriptor(D, Desc, MDSize, IsTemporary,
449448
Descriptor::UnknownSize{});
450-
}
451449
}
452450
}
453451

clang/lib/AST/ByteCode/Program.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
#include "Record.h"
2020
#include "Source.h"
2121
#include "llvm/ADT/DenseMap.h"
22-
#include "llvm/ADT/PointerUnion.h"
23-
#include "llvm/ADT/StringRef.h"
2422
#include "llvm/Support/Allocator.h"
25-
#include <map>
2623
#include <vector>
2724

2825
namespace clang {

0 commit comments

Comments
 (0)