[llvm] c9f6912 - [Coverity] Fix uninitialized scalar members in MC
Akshay Khadse via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 23 00:30:07 PDT 2023
Author: Akshay Khadse
Date: 2023-04-23T15:29:52+08:00
New Revision: c9f6912a3a831af2dcbb28d9bf53d7fb7b30b010
URL: https://github.com/llvm/llvm-project/commit/c9f6912a3a831af2dcbb28d9bf53d7fb7b30b010
DIFF: https://github.com/llvm/llvm-project/commit/c9f6912a3a831af2dcbb28d9bf53d7fb7b30b010.diff
LOG: [Coverity] Fix uninitialized scalar members in MC
This change fixes static code analysis errors
Reviewed By: pengfei
Differential Revision: https://reviews.llvm.org/D148814
Added:
Modified:
llvm/include/llvm/MC/MCAsmMacro.h
llvm/include/llvm/MC/MCDwarf.h
llvm/include/llvm/MC/MCMachObjectWriter.h
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCParser/MCAsmLexer.h
llvm/include/llvm/MC/MCParser/MCParsedAsmOperand.h
llvm/include/llvm/MC/MCRegisterInfo.h
llvm/include/llvm/MC/MCSection.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp
llvm/lib/MC/XCOFFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmMacro.h b/llvm/include/llvm/MC/MCAsmMacro.h
index e3d6a858132df..3e8d898af308a 100644
--- a/llvm/include/llvm/MC/MCAsmMacro.h
+++ b/llvm/include/llvm/MC/MCAsmMacro.h
@@ -63,7 +63,7 @@ class AsmToken {
};
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 cbc3b8cff2444..ce9c154d34547 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -506,7 +506,7 @@ class MCCFIInstruction {
int Offset;
unsigned Register2;
};
- unsigned AddressSpace;
+ unsigned AddressSpace = ~0u;
std::vector<char> Values;
std::string Comment;
diff --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h
index 15e4652bc05da..05d816671b1a4 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 52ddaf3488299..bd75c357ea378 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<MCSymbol *, 2> PendingLabels;
SmallSetVector<MCSection *, 4> 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 850a9cffe73a4..9affb1f980bb0 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 22f66a011ece5..0c9668904e826 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 11265ba9b0677..cafa0ba4913fc 100644
--- a/llvm/include/llvm/MC/MCRegisterInfo.h
+++ b/llvm/include/llvm/MC/MCRegisterInfo.h
@@ -243,7 +243,7 @@ class MCRegisterInfo {
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_
diff list_iterator(MCRegisterInfo::DiffListIterator Iter) : Iter(Iter) {}
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index f55ebf89b69f8..90bc48ec185ca 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -74,7 +74,7 @@ class MCSection {
/// 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 cb1c0c302ff24..ea2091dffe8b3 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<const MCSectionELF *> SectionTable;
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 25bd1b8737784..c18a963280911 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -79,7 +79,7 @@ class COFFSymbol {
using AuxiliarySymbols = SmallVector<AuxSymbol, 1>;
name Name;
- int Index;
+ int Index = 0;
AuxiliarySymbols Aux;
COFFSymbol *Other = nullptr;
COFFSection *Section = nullptr;
@@ -115,7 +115,7 @@ class COFFSection {
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 6452050d5941e..4b426604c0957 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;
More information about the llvm-commits
mailing list