[llvm] 3649fb1 - Fixed some errors detected by PVS Studio
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 9 08:20:11 PDT 2021
Author: Dávid Bolvanský
Date: 2021-10-09T17:20:04+02:00
New Revision: 3649fb14d126004373f7bcdfbd58266c7937dcb7
URL: https://github.com/llvm/llvm-project/commit/3649fb14d126004373f7bcdfbd58266c7937dcb7
DIFF: https://github.com/llvm/llvm-project/commit/3649fb14d126004373f7bcdfbd58266c7937dcb7.diff
LOG: Fixed some errors detected by PVS Studio
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/Support/raw_ostream.cpp
llvm/lib/XRay/InstrumentationMap.cpp
llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index ecc888d41329d..cf787374517c6 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -662,7 +662,7 @@ RTLIB::Libcall RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
/// InitCmpLibcallCCs - Set default comparison libcall CC.
static void InitCmpLibcallCCs(ISD::CondCode *CCs) {
- memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
+ std::fill(CCs, CCs + RTLIB::UNKNOWN_LIBCALL, ISD::SETCC_INVALID);
CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
index 98a8acaffd60d..0584966a98c58 100644
--- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
@@ -334,8 +334,6 @@ static uint16_t toSecMapFlags(uint32_t Flags) {
Ret |= static_cast<uint16_t>(OMFSegDescFlags::Write);
if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
- if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
- Ret |= static_cast<uint16_t>(OMFSegDescFlags::Execute);
if (!(Flags & COFF::IMAGE_SCN_MEM_16BIT))
Ret |= static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit);
diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
index 8f64a0ad4d7b4..cb2b8592ebc9d 100644
--- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
@@ -664,7 +664,7 @@ EHFrameEdgeFixer::readEncodedPointer(uint8_t PointerEncoding,
EffectiveType = (PointerSize == 8) ? DW_EH_PE_udata8 : DW_EH_PE_udata4;
JITTargetAddress Addr;
- Edge::Kind PointerEdgeKind;
+ Edge::Kind PointerEdgeKind == Edge::Invalid;
switch (EffectiveType) {
case DW_EH_PE_udata4: {
uint32_t Val;
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index f8f2f0c12020a..e378be3892fee 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1380,9 +1380,6 @@ void ELFState<ELFT>::writeSectionContent(
if (!Section.Entries)
return;
- if (!Section.Entries)
- return;
-
for (const ELFYAML::StackSizeEntry &E : *Section.Entries) {
CBA.write<uintX_t>(E.Address, ELFT::TargetEndianness);
SHeader.sh_size += sizeof(uintX_t) + CBA.writeULEB128(E.Size);
@@ -1488,9 +1485,6 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
if (!Section.Bucket)
return;
- if (!Section.Bucket)
- return;
-
CBA.write<uint32_t>(
Section.NBucket.getValueOr(llvm::yaml::Hex64(Section.Bucket->size())),
ELFT::TargetEndianness);
@@ -1663,9 +1657,6 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
if (!Section.Symbols)
return;
- if (!Section.Symbols)
- return;
-
for (StringRef Sym : *Section.Symbols)
SHeader.sh_size +=
CBA.writeULEB128(toSymbolIndex(Sym, Section.Name, /*IsDynamic=*/false));
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index ac6dd6b0f8472..4590a3d19b0dd 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -185,7 +185,7 @@ raw_ostream &raw_ostream::write_escaped(StringRef Str,
// Write out the escaped representation.
if (UseHexEscapes) {
*this << '\\' << 'x';
- *this << hexdigit((c >> 4 & 0xF));
+ *this << hexdigit((c >> 4) & 0xF);
*this << hexdigit((c >> 0) & 0xF);
} else {
// Always use a full 3-character octal escape.
diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp
index e6534e5a7be7c..089591c4a7df4 100644
--- a/llvm/lib/XRay/InstrumentationMap.cpp
+++ b/llvm/lib/XRay/InstrumentationMap.cpp
@@ -190,7 +190,7 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
SledEntry::FunctionKinds::TAIL,
SledEntry::FunctionKinds::LOG_ARGS_ENTER,
SledEntry::FunctionKinds::CUSTOM_EVENT};
- if (Kind >= sizeof(Kinds))
+ if (Kind >= sizeof(Kinds) / sizeof(Kinds[0]))
return errorCodeToError(
std::make_error_code(std::errc::executable_format_error));
Entry.Kind = Kinds[Kind];
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index 8f6d44e60939d..21339a3f8f3d8 100644
--- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -1024,7 +1024,7 @@ int main(int argc, char **argv) {
Timers = ShowTimes ? std::make_unique<RTDyldTimers>() : nullptr;
- int Result;
+ int Result = 0;
switch (Action) {
case AC_Execute:
Result = executeInput();
More information about the llvm-commits
mailing list