From 56a725ae5e1d5ad8673658bbd7717a9fe1ef054f Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sat, 9 Nov 2019 13:00:36 +0000 Subject: [PATCH] Remarks - fix static analyzer warnings. NFCI. - Fix uninitialized variable warnings. - Reuse BitstreamEntry iterator to avoid Wshadow warning. - Match declaration + definition arg names in BitstreamRemarkParser::processCommonMeta - Make BitstreamRemarkParser(StringRef) constructor explicit --- llvm/include/llvm/Bitstream/BitstreamReader.h | 2 +- llvm/include/llvm/Remarks/Remark.h | 4 ++-- llvm/lib/Remarks/BitstreamRemarkParser.cpp | 8 ++++---- llvm/lib/Remarks/BitstreamRemarkParser.h | 9 +++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/Bitstream/BitstreamReader.h b/llvm/include/llvm/Bitstream/BitstreamReader.h index b49a969a2d8b..c476f60420fa 100644 --- a/llvm/include/llvm/Bitstream/BitstreamReader.h +++ b/llvm/include/llvm/Bitstream/BitstreamReader.h @@ -39,7 +39,7 @@ public: /// This contains information emitted to BLOCKINFO_BLOCK blocks. These /// describe abbreviations that all blocks of the specified ID inherit. struct BlockInfo { - unsigned BlockID; + unsigned BlockID = 0; std::vector> Abbrevs; std::string Name; std::vector> RecordNames; diff --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h index 73b2680e98da..6211db4a8e96 100644 --- a/llvm/include/llvm/Remarks/Remark.h +++ b/llvm/include/llvm/Remarks/Remark.h @@ -30,8 +30,8 @@ constexpr uint64_t CurrentRemarkVersion = 0; struct RemarkLocation { /// Absolute path of the source file corresponding to this remark. StringRef SourceFilePath; - unsigned SourceLine; - unsigned SourceColumn; + unsigned SourceLine = 0; + unsigned SourceColumn = 0; }; // Create wrappers for C Binding types (see CBindingWrapping.h). diff --git a/llvm/lib/Remarks/BitstreamRemarkParser.cpp b/llvm/lib/Remarks/BitstreamRemarkParser.cpp index 1cfde1192229..dfad5902545a 100644 --- a/llvm/lib/Remarks/BitstreamRemarkParser.cpp +++ b/llvm/lib/Remarks/BitstreamRemarkParser.cpp @@ -174,7 +174,7 @@ static Error parseBlock(T &ParserHelper, unsigned BlockID, // Stop when there is nothing to read anymore or when we encounter an // END_BLOCK. while (!Stream.AtEndOfStream()) { - Expected Next = Stream.advance(); + Next = Stream.advance(); if (!Next) return Next.takeError(); switch (Next->Kind) { @@ -366,15 +366,15 @@ Error BitstreamRemarkParser::parseMeta() { } Error BitstreamRemarkParser::processCommonMeta( - BitstreamMetaParserHelper &MetaHelper) { - if (Optional Version = MetaHelper.ContainerVersion) + BitstreamMetaParserHelper &Helper) { + if (Optional Version = Helper.ContainerVersion) ContainerVersion = *Version; else return createStringError( std::make_error_code(std::errc::illegal_byte_sequence), "Error while parsing BLOCK_META: missing container version."); - if (Optional Type = MetaHelper.ContainerType) { + if (Optional Type = Helper.ContainerType) { // Always >= BitstreamRemarkContainerType::First since it's unsigned. if (*Type > static_cast(BitstreamRemarkContainerType::Last)) return createStringError( diff --git a/llvm/lib/Remarks/BitstreamRemarkParser.h b/llvm/lib/Remarks/BitstreamRemarkParser.h index 7c9cc2f1e7db..749219fc5155 100644 --- a/llvm/lib/Remarks/BitstreamRemarkParser.h +++ b/llvm/lib/Remarks/BitstreamRemarkParser.h @@ -34,15 +34,16 @@ struct BitstreamRemarkParser : public RemarkParser { std::unique_ptr TmpRemarkBuffer; /// The common metadata used to decide how to parse the buffer. /// This is filled when parsing the metadata block. - uint64_t ContainerVersion; - uint64_t RemarkVersion; - BitstreamRemarkContainerType ContainerType; + uint64_t ContainerVersion = 0; + uint64_t RemarkVersion = 0; + BitstreamRemarkContainerType ContainerType = + BitstreamRemarkContainerType::Standalone; /// Wether the parser is ready to parse remarks. bool ReadyToParseRemarks = false; /// Create a parser that expects to find a string table embedded in the /// stream. - BitstreamRemarkParser(StringRef Buf) + explicit BitstreamRemarkParser(StringRef Buf) : RemarkParser(Format::Bitstream), ParserHelper(Buf) {} /// Create a parser that uses a pre-parsed string table. -- GitLab