Skip to content

Commit 01b88dd

Browse files
committed
[NFC] Remove unused variables declared in conditions
D152495 makes clang warn on unused variables that are declared in conditions like `if (int var = init) {}` This patch is an NFC fix to suppress the new warning in llvm,clang,lld builds to pass CI in the above patch. Differential Revision: https://reviews.llvm.org/D158016
1 parent c948e3e commit 01b88dd

File tree

17 files changed

+25
-26
lines changed

17 files changed

+25
-26
lines changed

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3928,7 +3928,7 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>,
39283928
AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
39293929
callee, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCMessageExpr, CallExpr),
39303930
internal::Matcher<Decl>, InnerMatcher, 1) {
3931-
if (const auto *CallNode = dyn_cast<CallExpr>(&Node))
3931+
if (isa<CallExpr>(&Node))
39323932
return callExpr(hasDeclaration(InnerMatcher))
39333933
.matches(Node, Finder, Builder);
39343934
else {

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ bool ByteCodeStmtGen<Emitter>::visitIfStmt(const IfStmt *IS) {
341341
return IS->getElse() ? visitStmt(IS->getElse()) : true;
342342

343343
if (auto *CondInit = IS->getInit())
344-
if (!visitStmt(IS->getInit()))
344+
if (!visitStmt(CondInit))
345345
return false;
346346

347347
if (const DeclStmt *CondDecl = IS->getConditionVariableDeclStmt())

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
13531353
for (StringRef OffloadObject : CGOpts.OffloadObjects) {
13541354
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
13551355
llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1356-
if (std::error_code EC = ObjectOrErr.getError()) {
1356+
if (ObjectOrErr.getError()) {
13571357
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
13581358
"could not open '%0' for embedding");
13591359
Diags.Report(DiagID) << OffloadObject;

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
15571557
PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
15581558

15591559
llvm::sys::fs::UniqueID ID;
1560-
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
1560+
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
15611561
PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
15621562
}
15631563

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7423,7 +7423,7 @@ void CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
74237423

74247424
// Get the UniqueID for the file containing the decl.
74257425
llvm::sys::fs::UniqueID ID;
7426-
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
7426+
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
74277427
PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false);
74287428
assert(PLoc.isValid() && "Source location is expected to be valid.");
74297429
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
629629
const char *CubinF =
630630
Args.MakeArgString(getToolChain().getDriver().GetTemporaryPath(
631631
llvm::sys::path::stem(InputFile), "cubin"));
632-
if (std::error_code EC =
633-
llvm::sys::fs::copy_file(InputFile, C.addTempFile(CubinF)))
632+
if (llvm::sys::fs::copy_file(InputFile, C.addTempFile(CubinF)))
634633
continue;
635634

636635
CmdArgs.push_back(CubinF);

clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
381381
SymbolRef RetSym = Call.getReturnValue().getAsSymbol();
382382
Notes.push_back([RetSym, FuncDecl](BugReport &BR) -> std::string {
383383
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
384-
if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) {
384+
if (PathBR->getInterestingnessKind(RetSym)) {
385385
std::string SBuf;
386386
llvm::raw_string_ostream OS(SBuf);
387387
OS << "Function '" << FuncDecl->getDeclName()
@@ -397,7 +397,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
397397
SymbolRef RetSym = Call.getReturnValue().getAsSymbol();
398398
Notes.push_back([RetSym, FuncDecl](BugReport &BR) -> std::string {
399399
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
400-
if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) {
400+
if (PathBR->getInterestingnessKind(RetSym)) {
401401
std::string SBuf;
402402
llvm::raw_string_ostream OS(SBuf);
403403
OS << "Function '" << FuncDecl->getDeclName()
@@ -431,7 +431,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
431431
} else {
432432
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
433433
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
434-
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
434+
if (PathBR->getInterestingnessKind(Handle)) {
435435
std::string SBuf;
436436
llvm::raw_string_ostream OS(SBuf);
437437
OS << "Handle released through " << ParamDiagIdx
@@ -445,7 +445,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
445445
} else if (hasFuchsiaAttr<AcquireHandleAttr>(PVD)) {
446446
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
447447
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
448-
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
448+
if (PathBR->getInterestingnessKind(Handle)) {
449449
std::string SBuf;
450450
llvm::raw_string_ostream OS(SBuf);
451451
OS << "Handle allocated through " << ParamDiagIdx
@@ -459,7 +459,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
459459
} else if (hasFuchsiaUnownedAttr<AcquireHandleAttr>(PVD)) {
460460
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
461461
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
462-
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
462+
if (PathBR->getInterestingnessKind(Handle)) {
463463
std::string SBuf;
464464
llvm::raw_string_ostream OS(SBuf);
465465
OS << "Unowned handle allocated through " << ParamDiagIdx

clang/lib/StaticAnalyzer/Checkers/Yaml.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ std::optional<T> getConfiguration(CheckerManager &Mgr, Checker *Chk,
3535
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
3636
FS->getBufferForFile(ConfigFile.str());
3737

38-
if (std::error_code ec = Buffer.getError()) {
38+
if (Buffer.getError()) {
3939
Mgr.reportInvalidCheckerOptionValue(Chk, Option,
4040
"a valid filename instead of '" +
4141
std::string(ConfigFile) + "'");

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ class ResourceDirectoryCache {
263263
OutputFile.str(),
264264
ErrorFile.str(),
265265
};
266-
if (const int RC = llvm::sys::ExecuteAndWait(
267-
ClangBinaryPath, PrintResourceDirArgs, {}, Redirects)) {
266+
if (llvm::sys::ExecuteAndWait(ClangBinaryPath, PrintResourceDirArgs, {},
267+
Redirects)) {
268268
auto ErrorBuf = llvm::MemoryBuffer::getFile(ErrorFile.c_str());
269269
llvm::errs() << ErrorBuf.get()->getBuffer();
270270
return "";

lld/MachO/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
311311
path::filename(path).starts_with("libswift");
312312
if ((isCommandLineLoad && config->allLoad) ||
313313
loadType == LoadType::CommandLineForce || isLCLinkerForceLoad) {
314-
if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
314+
if (readFile(path)) {
315315
Error e = Error::success();
316316
for (const object::Archive::Child &c : file->getArchive().children(e)) {
317317
StringRef reason;
@@ -341,7 +341,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
341341

342342
// TODO: no need to look for ObjC sections for a given archive member if
343343
// we already found that it contains an ObjC symbol.
344-
if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
344+
if (readFile(path)) {
345345
Error e = Error::success();
346346
for (const object::Archive::Child &c : file->getArchive().children(e)) {
347347
Expected<MemoryBufferRef> mb = c.getMemoryBufferRef();

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) {
11871187
// So, we walk the CU's and their child DI's manually, looking for the
11881188
// specific global variable.
11891189
for (std::unique_ptr<DWARFUnit> &CU : compile_units()) {
1190-
if (DWARFDie Die = CU->getVariableForAddress(Address)) {
1190+
if (CU->getVariableForAddress(Address)) {
11911191
return static_cast<DWARFCompileUnit *>(CU.get());
11921192
}
11931193
}

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ void DWARFUnit::updateVariableDieMap(DWARFDie Die) {
828828
// no type), then we use a size of one to still allow symbolization of the
829829
// exact address.
830830
uint64_t GVSize = 1;
831-
if (DWARFDie BaseType = Die.getAttributeValueAsReferencedDie(DW_AT_type))
831+
if (Die.getAttributeValueAsReferencedDie(DW_AT_type))
832832
if (std::optional<uint64_t> Size = Die.getTypeSize(getAddressByteSize()))
833833
GVSize = *Size;
834834

llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Error DwarfTransformer::convert(uint32_t NumThreads, raw_ostream *OS) {
504504
size_t NumBefore = Gsym.getNumFunctionInfos();
505505
auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
506506
DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
507-
if (std::optional<uint64_t> DWOId = DwarfUnit.getDWOId()) {
507+
if (DwarfUnit.getDWOId()) {
508508
DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
509509
if (OS && !DWOCU->isDWOUnit()) {
510510
std::string DWOName = dwarf::toString(

llvm/lib/IR/PrintPasses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ std::string llvm::doSystemDiff(StringRef Before, StringRef After,
212212
static SmallVector<int> FD{-1, -1, -1};
213213
SmallVector<StringRef> SR{Before, After};
214214
static SmallVector<std::string> FileName{"", "", ""};
215-
if (auto Err = prepareTempFiles(FD, SR, FileName))
215+
if (prepareTempFiles(FD, SR, FileName))
216216
return "Unable to create temporary file.";
217217

218218
static ErrorOr<std::string> DiffExe = sys::findProgramByName(DiffBinary);
@@ -238,7 +238,7 @@ std::string llvm::doSystemDiff(StringRef Before, StringRef After,
238238
else
239239
return "Unable to read result.";
240240

241-
if (auto Err = cleanUpTempFiles(FileName))
241+
if (cleanUpTempFiles(FileName))
242242
return "Unable to remove temporary file.";
243243

244244
return Diff;

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
501501
static SmallVector<int> FD{-1};
502502
SmallVector<StringRef> SR{S};
503503
static SmallVector<std::string> FileName{""};
504-
if (auto Err = prepareTempFiles(FD, SR, FileName)) {
504+
if (prepareTempFiles(FD, SR, FileName)) {
505505
dbgs() << "Unable to create temporary file.";
506506
return;
507507
}
@@ -518,7 +518,7 @@ void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
518518
return;
519519
}
520520

521-
if (auto Err = cleanUpTempFiles(FileName))
521+
if (cleanUpTempFiles(FileName))
522522
dbgs() << "Unable to remove temporary file.";
523523
}
524524

llvm/lib/Support/VirtualFileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ std::error_code RedirectingFileSystem::isLocal(const Twine &Path_,
13371337
SmallString<256> Path;
13381338
Path_.toVector(Path);
13391339

1340-
if (std::error_code EC = makeCanonical(Path))
1340+
if (makeCanonical(Path))
13411341
return {};
13421342

13431343
return ExternalFS->isLocal(Path, Result);

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
812812
// Handles DWO sections that can either be in .o, .dwo or .dwp files.
813813
for (const auto &CompilationUnit : DebugContext->compile_units()) {
814814
DWARFUnit *const DwarfUnit = CompilationUnit.get();
815-
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
815+
if (DwarfUnit->getDWOId()) {
816816
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
817817
if (!DWOCU->isDWOUnit()) {
818818
std::string DWOName = dwarf::toString(

0 commit comments

Comments
 (0)