From c9f6912a3a831af2dcbb28d9bf53d7fb7b30b010 Mon Sep 17 00:00:00 2001 From: Akshay Khadse Date: Sun, 23 Apr 2023 15:28:59 +0800 Subject: [PATCH] [Coverity] Fix uninitialized scalar members in MC This change fixes static code analysis errors Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D148814 --- llvm/include/llvm/MC/MCAsmMacro.h | 2 +- llvm/include/llvm/MC/MCDwarf.h | 2 +- llvm/include/llvm/MC/MCMachObjectWriter.h | 2 +- llvm/include/llvm/MC/MCObjectStreamer.h | 2 +- llvm/include/llvm/MC/MCParser/MCAsmLexer.h | 2 +- llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h | 2 +- llvm/include/llvm/MC/MCRegisterInfo.h | 2 +- llvm/include/llvm/MC/MCSection.h | 2 +- llvm/lib/MC/ELFObjectWriter.cpp | 6 +++--- llvm/lib/MC/WinCOFFObjectWriter.cpp | 4 ++-- llvm/lib/MC/XCOFFObjectWriter.cpp | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/MC/MCAsmMacro.h b/llvm/include/llvm/MC/MCAsmMacro.h index e3d6a85..3e8d898 100644 --- a/llvm/include/llvm/MC/MCAsmMacro.h +++ b/llvm/include/llvm/MC/MCAsmMacro.h @@ -63,7 +63,7 @@ public: }; private: - TokenKind Kind; + TokenKind Kind = TokenKind::Eof; /// A reference to the entire token contents; this is always a pointer into /// a memory buffer owned by the source manager. diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h index cbc3b8c..ce9c154 100644 --- a/llvm/include/llvm/MC/MCDwarf.h +++ b/llvm/include/llvm/MC/MCDwarf.h @@ -506,7 +506,7 @@ private: int Offset; unsigned Register2; }; - unsigned AddressSpace; + unsigned AddressSpace = ~0u; std::vector Values; std::string Comment; diff --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h index 15e4652..05d8166 100644 --- a/llvm/include/llvm/MC/MCMachObjectWriter.h +++ b/llvm/include/llvm/MC/MCMachObjectWriter.h @@ -32,7 +32,7 @@ class MCMachObjectTargetWriter : public MCObjectTargetWriter { protected: uint32_t CPUSubtype; public: - unsigned LocalDifference_RIT; + unsigned LocalDifference_RIT = 0; protected: MCMachObjectTargetWriter(bool Is64Bit_, uint32_t CPUType_, diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 52ddaf3..bd75c35 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -46,7 +46,7 @@ class MCObjectStreamer : public MCStreamer { bool EmitDebugFrame; SmallVector PendingLabels; SmallSetVector PendingLabelSections; - unsigned CurSubsectionIdx; + unsigned CurSubsectionIdx = 0; struct PendingMCFixup { const MCSymbol *Sym; MCFixup Fixup; diff --git a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h index 850a9cf..9affb1f 100644 --- a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h @@ -45,7 +45,7 @@ class MCAsmLexer { protected: // Can only create subclasses. const char *TokStart = nullptr; bool SkipSpace = true; - bool AllowAtInIdentifier; + bool AllowAtInIdentifier = false; bool AllowHashInIdentifier = false; bool IsAtStartOfStatement = true; bool LexMasmHexFloats = false; diff --git a/llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h b/llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h index 22f66a0..0c96689 100644 --- a/llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h +++ b/llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h @@ -24,7 +24,7 @@ class raw_ostream; class MCParsedAsmOperand { /// MCOperandNum - The corresponding MCInst operand number. Only valid when /// parsing MS-style inline assembly. - unsigned MCOperandNum; + unsigned MCOperandNum = ~0u; /// Constraint - The constraint on this operand. Only valid when parsing /// MS-style inline assembly. diff --git a/llvm/include/llvm/MC/MCRegisterInfo.h b/llvm/include/llvm/MC/MCRegisterInfo.h index 11265ba..cafa0ba 100644 --- a/llvm/include/llvm/MC/MCRegisterInfo.h +++ b/llvm/include/llvm/MC/MCRegisterInfo.h @@ -243,7 +243,7 @@ public: std::forward_iterator_tag, MCPhysReg> { MCRegisterInfo::DiffListIterator Iter; /// Current value as MCPhysReg, so we can return a reference to it. - MCPhysReg Val; + MCPhysReg Val = 0; protected: mc_difflist_iterator(MCRegisterInfo::DiffListIterator Iter) : Iter(Iter) {} diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index f55ebf8..90bc48e 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -74,7 +74,7 @@ private: /// The section index in the assemblers section list. unsigned Ordinal = 0; /// The index of this section in the layout order. - unsigned LayoutOrder; + unsigned LayoutOrder = 0; /// Keeping track of bundle-locked state. BundleLockStateType BundleLockState = NotBundleLocked; diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index cb1c0c3..ea2091d 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -128,11 +128,11 @@ struct ELFWriter { /// @} // This holds the symbol table index of the last local symbol. - unsigned LastLocalSymbolIndex; + unsigned LastLocalSymbolIndex = ~0u; // This holds the .strtab section index. - unsigned StringTableIndex; + unsigned StringTableIndex = ~0u; // This holds the .symtab section index. - unsigned SymbolTableIndex; + unsigned SymbolTableIndex = ~0u; // Sections in the order they are to be output in the section table. std::vector SectionTable; diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 25bd1b8..c18a963 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -79,7 +79,7 @@ public: using AuxiliarySymbols = SmallVector; name Name; - int Index; + int Index = 0; AuxiliarySymbols Aux; COFFSymbol *Other = nullptr; COFFSection *Section = nullptr; @@ -115,7 +115,7 @@ public: COFF::section Header = {}; std::string Name; - int Number; + int Number = 0; MCSectionCOFF const *MCSection = nullptr; COFFSymbol *Symbol = nullptr; relocations Relocations; diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp index 6452050..4b42660 100644 --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -206,7 +206,7 @@ struct DwarfSectionEntry : public SectionEntry { struct ExceptionTableEntry { const MCSymbol *Trap; - uint64_t TrapAddress; + uint64_t TrapAddress = ~0ul; unsigned Lang; unsigned Reason; -- 2.7.4