From 8b6140b9f93e9f96824432cc24f089b8a921e36a Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 26 Jun 2024 08:13:03 -0700 Subject: [PATCH 1/2] [AsmParser] Use range-based for loops (NFC) --- llvm/lib/AsmParser/LLParser.cpp | 71 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 059d42d9faa7f..5cd04674ecbbc 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3293,17 +3293,16 @@ bool LLParser::parseFunctionType(Type *&Result) { return true; // Reject names on the arguments lists. - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { - if (!ArgList[i].Name.empty()) - return error(ArgList[i].Loc, "argument name invalid in function type"); - if (ArgList[i].Attrs.hasAttributes()) - return error(ArgList[i].Loc, - "argument attributes invalid in function type"); + for (const ArgInfo &Arg : ArgList) { + if (!Arg.Name.empty()) + return error(Arg.Loc, "argument name invalid in function type"); + if (Arg.Attrs.hasAttributes()) + return error(Arg.Loc, "argument attributes invalid in function type"); } SmallVector ArgListTy; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) - ArgListTy.push_back(ArgList[i].Ty); + for (const ArgInfo &Arg : ArgList) + ArgListTy.push_back(Arg.Ty); Result = FunctionType::get(Result, ArgListTy, IsVarArg); return false; @@ -6404,9 +6403,9 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine, std::vector ParamTypeList; SmallVector Attrs; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { - ParamTypeList.push_back(ArgList[i].Ty); - Attrs.push_back(ArgList[i].Attrs); + for (const ArgInfo &Arg : ArgList) { + ParamTypeList.push_back(Arg.Ty); + Attrs.push_back(Arg.Attrs); } AttributeList PAL = @@ -7230,8 +7229,8 @@ bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) { return true; IndirectBrInst *IBI = IndirectBrInst::Create(Address, DestList.size()); - for (unsigned i = 0, e = DestList.size(); i != e; ++i) - IBI->addDestination(DestList[i]); + for (BasicBlock *Dest : DestList) + IBI->addDestination(Dest); Inst = IBI; return false; } @@ -7246,8 +7245,8 @@ bool LLParser::resolveFunctionType(Type *RetType, if (!FuncTy) { // Pull out the types of all of the arguments... std::vector ParamTypes; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) - ParamTypes.push_back(ArgList[i].V->getType()); + for (const ParamInfo &Arg : ArgList) + ParamTypes.push_back(Arg.V->getType()); if (!FunctionType::isValidReturnType(RetType)) return true; @@ -7310,19 +7309,19 @@ bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) { // correctly. Also, gather any parameter attributes. FunctionType::param_iterator I = Ty->param_begin(); FunctionType::param_iterator E = Ty->param_end(); - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { + for (const ParamInfo &Arg : ArgList) { Type *ExpectedTy = nullptr; if (I != E) { ExpectedTy = *I++; } else if (!Ty->isVarArg()) { - return error(ArgList[i].Loc, "too many arguments specified"); + return error(Arg.Loc, "too many arguments specified"); } - if (ExpectedTy && ExpectedTy != ArgList[i].V->getType()) - return error(ArgList[i].Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); - Args.push_back(ArgList[i].V); - ArgAttrs.push_back(ArgList[i].Attrs); + if (ExpectedTy && ExpectedTy != Arg.V->getType()) + return error(Arg.Loc, "argument is not of expected type '" + + getTypeString(ExpectedTy) + "'"); + Args.push_back(Arg.V); + ArgAttrs.push_back(Arg.Attrs); } if (I != E) @@ -7623,19 +7622,19 @@ bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) { // correctly. Also, gather any parameter attributes. FunctionType::param_iterator I = Ty->param_begin(); FunctionType::param_iterator E = Ty->param_end(); - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { + for (const ParamInfo &Arg : ArgList) { Type *ExpectedTy = nullptr; if (I != E) { ExpectedTy = *I++; } else if (!Ty->isVarArg()) { - return error(ArgList[i].Loc, "too many arguments specified"); + return error(Arg.Loc, "too many arguments specified"); } - if (ExpectedTy && ExpectedTy != ArgList[i].V->getType()) - return error(ArgList[i].Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); - Args.push_back(ArgList[i].V); - ArgAttrs.push_back(ArgList[i].Attrs); + if (ExpectedTy && ExpectedTy != Arg.V->getType()) + return error(Arg.Loc, "argument is not of expected type '" + + getTypeString(ExpectedTy) + "'"); + Args.push_back(Arg.V); + ArgAttrs.push_back(Arg.Attrs); } if (I != E) @@ -8018,19 +8017,19 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS, // correctly. Also, gather any parameter attributes. FunctionType::param_iterator I = Ty->param_begin(); FunctionType::param_iterator E = Ty->param_end(); - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { + for (const ParamInfo &Arg : ArgList) { Type *ExpectedTy = nullptr; if (I != E) { ExpectedTy = *I++; } else if (!Ty->isVarArg()) { - return error(ArgList[i].Loc, "too many arguments specified"); + return error(Arg.Loc, "too many arguments specified"); } - if (ExpectedTy && ExpectedTy != ArgList[i].V->getType()) - return error(ArgList[i].Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); - Args.push_back(ArgList[i].V); - Attrs.push_back(ArgList[i].Attrs); + if (ExpectedTy && ExpectedTy != Arg.V->getType()) + return error(Arg.Loc, "argument is not of expected type '" + + getTypeString(ExpectedTy) + "'"); + Args.push_back(Arg.V); + Attrs.push_back(Arg.Attrs); } if (I != E) From f3ef0db2fb8ba6d8bb7038f004e5708fc624d169 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 2 Jul 2024 19:08:59 -0700 Subject: [PATCH 2/2] Fix formatting. --- llvm/lib/AsmParser/LLParser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 5cd04674ecbbc..87cd8aac8d035 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -7319,7 +7319,7 @@ bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) { if (ExpectedTy && ExpectedTy != Arg.V->getType()) return error(Arg.Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); + getTypeString(ExpectedTy) + "'"); Args.push_back(Arg.V); ArgAttrs.push_back(Arg.Attrs); } @@ -7632,7 +7632,7 @@ bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) { if (ExpectedTy && ExpectedTy != Arg.V->getType()) return error(Arg.Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); + getTypeString(ExpectedTy) + "'"); Args.push_back(Arg.V); ArgAttrs.push_back(Arg.Attrs); } @@ -8027,7 +8027,7 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS, if (ExpectedTy && ExpectedTy != Arg.V->getType()) return error(Arg.Loc, "argument is not of expected type '" + - getTypeString(ExpectedTy) + "'"); + getTypeString(ExpectedTy) + "'"); Args.push_back(Arg.V); Attrs.push_back(Arg.Attrs); }