Thanks to visit codestin.com
Credit goes to github.com

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

17 files changed

Lines changed: 25 additions & 26 deletions

File tree

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();

0 commit comments

Comments
 (0)