Skip to content

Commit

Permalink
[NFC] Fix formatv() usage in preparation of validation (#106454)
Browse files Browse the repository at this point in the history
Fix several uses of formatv() that would be flagged as invalid by an
upcoming change that will add additional validation to formatv().
  • Loading branch information
jurahul authored Aug 29, 2024
1 parent 75e9d19 commit b75fe11
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool PlacementNewChecker::checkPlaceCapacityIsSufficient(
"Storage provided to placement new is only {0} bytes, "
"whereas the allocated array type requires more space for "
"internal needs",
SizeOfPlaceCI->getValue(), SizeOfTargetCI->getValue()));
SizeOfPlaceCI->getValue()));
else
Msg = std::string(llvm::formatv(
"Storage provided to placement new is only {0} bytes, "
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ DWARFUnit::GetDIE(dw_offset_t die_offset) {

if (!ContainsDIEOffset(die_offset)) {
GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
"GetDIE for DIE {0:x16} is outside of its CU {0:x16}", die_offset,
"GetDIE for DIE {0:x16} is outside of its CU {1:x16}", die_offset,
GetOffset());
return DWARFDIE(); // Not found
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,8 +1518,7 @@ DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) {
error() << formatv("NameIndex @ {0:x}: Indexing multiple compile units "
"and abbreviation {1:x} has no DW_IDX_compile_unit "
"or DW_IDX_type_unit attribute.\n",
NI.getUnitOffset(), Abbrev.Code,
dwarf::DW_IDX_compile_unit);
NI.getUnitOffset(), Abbrev.Code);
});
++NumErrors;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ bool ExplainOutputStyle::explainPdbBlockStatus() {
FileOffset, File.pdb().getFileSize());
return false;
}
P.formatLine("Block:Offset = {2:X-}:{1:X-4}.", FileOffset, pdbBlockOffset(),
pdbBlockIndex());
P.formatLine("Block:Offset = {0:X-}:{1:X-4}.", pdbBlockIndex(),
pdbBlockOffset());

bool IsFree = File.pdb().getMsfLayout().FreePageMap[pdbBlockIndex()];
P.formatLine("Address is in block {0} ({1}allocated).", pdbBlockIndex(),
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/IntrinsicEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ Intrinsic::getIntrinsicFor{1}Builtin(StringRef TargetPrefix,
const auto &[Map, CommonPrefix] = Entry;
if (TargetPrefix.empty())
continue;
OS << formatv(R"( {{"{0}", {0}Names, "{2}"},)", TargetPrefix,
TargetPrefix, CommonPrefix)
OS << formatv(R"( {{"{0}", {0}Names, "{1}"},)", TargetPrefix,
CommonPrefix)
<< "\n";
}
OS << " };\n";
Expand Down
4 changes: 2 additions & 2 deletions mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ ArrayAttr {0}::getIndexingMaps() {{
MLIRContext *context = getContext();
auto symbolBindings = getSymbolBindings(*this);
SmallVector<AffineMap> maps;
{2}
{1}
cached = Builder(context).getAffineMapArrayAttr(maps);
getOperation()->setAttr(memoizeAttr, cached);
return cached;
Expand Down Expand Up @@ -929,7 +929,7 @@ exprs.push_back(getAffineConstantExpr(cst{1}, context));
// TODO: This needs to be memoized and/or converted to non-parser based
// C++ codegen prior to real use.
os << llvm::formatv(structuredOpIndexingMapsFormat, className,
dimIdentsStr, interleaveToString(stmts, "\n "));
interleaveToString(stmts, "\n "));
}
} else {
os << llvm::formatv(rankPolyStructuredOpIndexingMapsFormat, className);
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static void emitOneCEnumFromConversion(const llvm::Record *record,
os << formatv(
"inline LLVM_ATTRIBUTE_UNUSED {0}::{1} convert{1}FromLLVM(int64_t "
"value) {{\n",
cppNamespace, cppClassName, llvmClass);
cppNamespace, cppClassName);
os << " switch (value) {\n";

for (const auto &enumerant : enumAttr.getAllCases()) {
Expand Down
13 changes: 6 additions & 7 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ void OpEmitter::genPropertiesSupport() {
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
{0}
};
{2};
{1};
)decl";
const char *attrGetNoDefaultFmt = R"decl(;
if (attr && ::mlir::failed(setFromAttr(prop.{0}, attr, emitError)))
Expand Down Expand Up @@ -1419,7 +1419,7 @@ void OpEmitter::genPropertiesSupport() {
&fctx.addSubst("_attr", propertyAttr)
.addSubst("_storage", propertyStorage)
.addSubst("_diag", propertyDiag)),
name, getAttr);
getAttr);
if (prop.hasStorageTypeValueOverride()) {
setPropMethod << formatv(attrGetDefaultFmt, name,
prop.getStorageTypeValueOverride());
Expand Down Expand Up @@ -2768,11 +2768,10 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder() {
<< "u && \"mismatched number of return types\");";
body << "\n " << builderOpState << ".addTypes(inferredReturnTypes);";

body << formatv(R"(
} else {{
body << R"(
} else {
::llvm::report_fatal_error("Failed to infer result type(s).");
})",
opClass.getClassName(), builderOpState);
})";
}

void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() {
Expand Down Expand Up @@ -3882,7 +3881,7 @@ void OpEmitter::genSuccessorVerifier(MethodBody &body) {

auto getSuccessor =
formatv(successor.isVariadic() ? "{0}()" : getSingleSuccessor,
successor.name, it.index())
successor.name)
.str();
auto constraintFn =
staticVerifierEmitter.getSuccessorConstraintFn(successor.constraint);
Expand Down
6 changes: 2 additions & 4 deletions mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ static void genCustomDirectiveParser(CustomDirective *dir, MethodBody &body,
" {0}Operands.append(subRange.begin(), subRange.end());\n"
" {0}OperandGroupSizes.push_back(subRange.size());\n"
" }\n",
var->name, var->constraint.getVariadicOfVariadicSegmentSizeAttr());
var->name);
}
} else if (auto *dir = dyn_cast<TypeDirective>(param)) {
ArgumentLengthKind lengthKind;
Expand Down Expand Up @@ -1575,9 +1575,7 @@ void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
ArgumentLengthKind lengthKind = getArgumentLengthKind(operand->getVar());
StringRef name = operand->getVar()->name;
if (lengthKind == ArgumentLengthKind::VariadicOfVariadic)
body << llvm::formatv(
variadicOfVariadicOperandParserCode, name,
operand->getVar()->constraint.getVariadicOfVariadicSegmentSizeAttr());
body << llvm::formatv(variadicOfVariadicOperandParserCode, name);
else if (lengthKind == ArgumentLengthKind::Variadic)
body << llvm::formatv(variadicOperandParserCode, name);
else if (lengthKind == ArgumentLengthKind::Optional)
Expand Down
3 changes: 1 addition & 2 deletions mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,7 @@ static void emitSerializationFunction(const Record *attrClass,
os << formatv(" (void)emitDebugLine(functionBody, {0}.getLoc());\n",
opVar);
os << formatv(" (void)encodeInstructionInto("
"functionBody, spirv::Opcode::{1}, {2});\n",
op.getQualCppClassName(),
"functionBody, spirv::Opcode::{0}, {1});\n",
record->getValueAsString("spirvOpName"), operands);
}

Expand Down

0 comments on commit b75fe11

Please sign in to comment.