Skip to content

Commit

Permalink
[NFC] Remove unused variables declared in conditions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hazohelet committed Aug 30, 2023
1 parent c948e3e commit 01b88dd
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/ASTMatchers/ASTMatchers.h
Expand Up @@ -3928,7 +3928,7 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>,
AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
callee, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCMessageExpr, CallExpr),
internal::Matcher<Decl>, InnerMatcher, 1) {
if (const auto *CallNode = dyn_cast<CallExpr>(&Node))
if (isa<CallExpr>(&Node))
return callExpr(hasDeclaration(InnerMatcher))
.matches(Node, Finder, Builder);
else {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeStmtGen.cpp
Expand Up @@ -341,7 +341,7 @@ bool ByteCodeStmtGen<Emitter>::visitIfStmt(const IfStmt *IS) {
return IS->getElse() ? visitStmt(IS->getElse()) : true;

if (auto *CondInit = IS->getInit())
if (!visitStmt(IS->getInit()))
if (!visitStmt(CondInit))
return false;

if (const DeclStmt *CondDecl = IS->getConditionVariableDeclStmt())
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -1353,7 +1353,7 @@ void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
for (StringRef OffloadObject : CGOpts.OffloadObjects) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
if (std::error_code EC = ObjectOrErr.getError()) {
if (ObjectOrErr.getError()) {
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
"could not open '%0' for embedding");
Diags.Report(DiagID) << OffloadObject;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGOpenMPRuntime.cpp
Expand Up @@ -1557,7 +1557,7 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);

llvm::sys::fs::UniqueID ID;
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -7423,7 +7423,7 @@ void CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream &OS,

// Get the UniqueID for the file containing the decl.
llvm::sys::fs::UniqueID ID;
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false);
assert(PLoc.isValid() && "Source location is expected to be valid.");
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Expand Up @@ -629,8 +629,7 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const char *CubinF =
Args.MakeArgString(getToolChain().getDriver().GetTemporaryPath(
llvm::sys::path::stem(InputFile), "cubin"));
if (std::error_code EC =
llvm::sys::fs::copy_file(InputFile, C.addTempFile(CubinF)))
if (llvm::sys::fs::copy_file(InputFile, C.addTempFile(CubinF)))
continue;

CmdArgs.push_back(CubinF);
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
Expand Up @@ -381,7 +381,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
SymbolRef RetSym = Call.getReturnValue().getAsSymbol();
Notes.push_back([RetSym, FuncDecl](BugReport &BR) -> std::string {
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) {
if (PathBR->getInterestingnessKind(RetSym)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
OS << "Function '" << FuncDecl->getDeclName()
Expand All @@ -397,7 +397,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
SymbolRef RetSym = Call.getReturnValue().getAsSymbol();
Notes.push_back([RetSym, FuncDecl](BugReport &BR) -> std::string {
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
if (auto IsInteresting = PathBR->getInterestingnessKind(RetSym)) {
if (PathBR->getInterestingnessKind(RetSym)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
OS << "Function '" << FuncDecl->getDeclName()
Expand Down Expand Up @@ -431,7 +431,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
} else {
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
if (PathBR->getInterestingnessKind(Handle)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
OS << "Handle released through " << ParamDiagIdx
Expand All @@ -445,7 +445,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
} else if (hasFuchsiaAttr<AcquireHandleAttr>(PVD)) {
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
if (PathBR->getInterestingnessKind(Handle)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
OS << "Handle allocated through " << ParamDiagIdx
Expand All @@ -459,7 +459,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
} else if (hasFuchsiaUnownedAttr<AcquireHandleAttr>(PVD)) {
Notes.push_back([Handle, ParamDiagIdx](BugReport &BR) -> std::string {
auto *PathBR = static_cast<PathSensitiveBugReport *>(&BR);
if (auto IsInteresting = PathBR->getInterestingnessKind(Handle)) {
if (PathBR->getInterestingnessKind(Handle)) {
std::string SBuf;
llvm::raw_string_ostream OS(SBuf);
OS << "Unowned handle allocated through " << ParamDiagIdx
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/Yaml.h
Expand Up @@ -35,7 +35,7 @@ std::optional<T> getConfiguration(CheckerManager &Mgr, Checker *Chk,
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
FS->getBufferForFile(ConfigFile.str());

if (std::error_code ec = Buffer.getError()) {
if (Buffer.getError()) {
Mgr.reportInvalidCheckerOptionValue(Chk, Option,
"a valid filename instead of '" +
std::string(ConfigFile) + "'");
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/clang-scan-deps/ClangScanDeps.cpp
Expand Up @@ -263,8 +263,8 @@ class ResourceDirectoryCache {
OutputFile.str(),
ErrorFile.str(),
};
if (const int RC = llvm::sys::ExecuteAndWait(
ClangBinaryPath, PrintResourceDirArgs, {}, Redirects)) {
if (llvm::sys::ExecuteAndWait(ClangBinaryPath, PrintResourceDirArgs, {},
Redirects)) {
auto ErrorBuf = llvm::MemoryBuffer::getFile(ErrorFile.c_str());
llvm::errs() << ErrorBuf.get()->getBuffer();
return "";
Expand Down
4 changes: 2 additions & 2 deletions lld/MachO/Driver.cpp
Expand Up @@ -311,7 +311,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
path::filename(path).starts_with("libswift");
if ((isCommandLineLoad && config->allLoad) ||
loadType == LoadType::CommandLineForce || isLCLinkerForceLoad) {
if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
if (readFile(path)) {
Error e = Error::success();
for (const object::Archive::Child &c : file->getArchive().children(e)) {
StringRef reason;
Expand Down Expand Up @@ -341,7 +341,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,

// TODO: no need to look for ObjC sections for a given archive member if
// we already found that it contains an ObjC symbol.
if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
if (readFile(path)) {
Error e = Error::success();
for (const object::Archive::Child &c : file->getArchive().children(e)) {
Expected<MemoryBufferRef> mb = c.getMemoryBufferRef();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Expand Up @@ -1187,7 +1187,7 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) {
// So, we walk the CU's and their child DI's manually, looking for the
// specific global variable.
for (std::unique_ptr<DWARFUnit> &CU : compile_units()) {
if (DWARFDie Die = CU->getVariableForAddress(Address)) {
if (CU->getVariableForAddress(Address)) {
return static_cast<DWARFCompileUnit *>(CU.get());
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Expand Up @@ -828,7 +828,7 @@ void DWARFUnit::updateVariableDieMap(DWARFDie Die) {
// no type), then we use a size of one to still allow symbolization of the
// exact address.
uint64_t GVSize = 1;
if (DWARFDie BaseType = Die.getAttributeValueAsReferencedDie(DW_AT_type))
if (Die.getAttributeValueAsReferencedDie(DW_AT_type))
if (std::optional<uint64_t> Size = Die.getTypeSize(getAddressByteSize()))
GVSize = *Size;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Expand Up @@ -504,7 +504,7 @@ Error DwarfTransformer::convert(uint32_t NumThreads, raw_ostream *OS) {
size_t NumBefore = Gsym.getNumFunctionInfos();
auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
if (std::optional<uint64_t> DWOId = DwarfUnit.getDWOId()) {
if (DwarfUnit.getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
if (OS && !DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/PrintPasses.cpp
Expand Up @@ -212,7 +212,7 @@ std::string llvm::doSystemDiff(StringRef Before, StringRef After,
static SmallVector<int> FD{-1, -1, -1};
SmallVector<StringRef> SR{Before, After};
static SmallVector<std::string> FileName{"", "", ""};
if (auto Err = prepareTempFiles(FD, SR, FileName))
if (prepareTempFiles(FD, SR, FileName))
return "Unable to create temporary file.";

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

if (auto Err = cleanUpTempFiles(FileName))
if (cleanUpTempFiles(FileName))
return "Unable to remove temporary file.";

return Diff;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Expand Up @@ -501,7 +501,7 @@ void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
static SmallVector<int> FD{-1};
SmallVector<StringRef> SR{S};
static SmallVector<std::string> FileName{""};
if (auto Err = prepareTempFiles(FD, SR, FileName)) {
if (prepareTempFiles(FD, SR, FileName)) {
dbgs() << "Unable to create temporary file.";
return;
}
Expand All @@ -518,7 +518,7 @@ void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
return;
}

if (auto Err = cleanUpTempFiles(FileName))
if (cleanUpTempFiles(FileName))
dbgs() << "Unable to remove temporary file.";
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/VirtualFileSystem.cpp
Expand Up @@ -1337,7 +1337,7 @@ std::error_code RedirectingFileSystem::isLocal(const Twine &Path_,
SmallString<256> Path;
Path_.toVector(Path);

if (std::error_code EC = makeCanonical(Path))
if (makeCanonical(Path))
return {};

return ExternalFS->isLocal(Path, Result);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-profgen/ProfiledBinary.cpp
Expand Up @@ -812,7 +812,7 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
// Handles DWO sections that can either be in .o, .dwo or .dwp files.
for (const auto &CompilationUnit : DebugContext->compile_units()) {
DWARFUnit *const DwarfUnit = CompilationUnit.get();
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
if (DwarfUnit->getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
Expand Down

0 comments on commit 01b88dd

Please sign in to comment.