0

Convert WARN_UNUSED_RESULT to [[nodiscard]] in //courgette.

This is an automated conversion produced by the script and command in
the attached bug.

Bug: 1287045
Change-Id: I9217c39f13991966e35ea1c4fc02e4229f7bf595
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387499
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Samuel Huang <huangs@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/main@{#959153}
This commit is contained in:
Daniel Cheng
2022-01-14 14:39:55 +00:00
committed by Chromium LUCI CQ
parent de189c5d2a
commit 8021cefa5e
7 changed files with 66 additions and 72 deletions

@ -113,11 +113,11 @@ class DisassemblerElf32 : public Disassembler {
virtual e_machine_values ElfEM() const = 0;
CheckBool IsValidTargetRVA(RVA rva) const WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool IsValidTargetRVA(RVA rva) const;
// Converts an ELF relocation instruction into an RVA.
virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
const WARN_UNUSED_RESULT = 0;
[[nodiscard]] virtual CheckBool RelToRVA(Elf32_Rel rel,
RVA* result) const = 0;
// Public for unittests only
std::vector<RVA>& Abs32Locations() { return abs32_locations_; }
@ -182,17 +182,17 @@ class DisassemblerElf32 : public Disassembler {
// Helpers for ParseFile().
virtual CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
InstructionReceptor* receptor) const
WARN_UNUSED_RESULT = 0;
[[nodiscard]] virtual CheckBool ParseRelocationSection(
const Elf32_Shdr* section_header,
InstructionReceptor* receptor) const = 0;
virtual CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
WARN_UNUSED_RESULT = 0;
[[nodiscard]] virtual CheckBool ParseRel32RelocsFromSection(
const Elf32_Shdr* section) = 0;
CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseAbs32Relocs();
// Extracts all rel32 TypedRVAs. Does not sort the result.
CheckBool ParseRel32RelocsFromSections() WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseRel32RelocsFromSections();
// Disassembler interfaces.
bool ExtractAbs32Locations() override;
@ -203,24 +203,24 @@ class DisassemblerElf32 : public Disassembler {
InstructionGenerator GetInstructionGenerator(
AssemblyProgram* program) override;
CheckBool ParseFile(AssemblyProgram* target,
InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseFile(AssemblyProgram* target,
InstructionReceptor* receptor) const;
CheckBool ParseProgbitsSection(
[[nodiscard]] CheckBool ParseProgbitsSection(
const Elf32_Shdr* section_header,
std::vector<FileOffset>::iterator* current_abs_offset,
std::vector<FileOffset>::iterator end_abs_offset,
std::vector<std::unique_ptr<TypedRVA>>::iterator* current_rel,
std::vector<std::unique_ptr<TypedRVA>>::iterator end_rel,
AssemblyProgram* program,
InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
InstructionReceptor* receptor) const;
CheckBool ParseSimpleRegion(FileOffset start_file_offset,
FileOffset end_file_offset,
InstructionReceptor* receptor) const
WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseSimpleRegion(
FileOffset start_file_offset,
FileOffset end_file_offset,
InstructionReceptor* receptor) const;
CheckBool CheckSection(RVA rva) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool CheckSection(RVA rva);
raw_ptr<const Elf32_Ehdr> header_;

@ -49,13 +49,12 @@ class DisassemblerElf32X86 : public DisassemblerElf32 {
protected:
// DisassemblerElf32 interfaces.
CheckBool RelToRVA(Elf32_Rel rel,
RVA* result) const override WARN_UNUSED_RESULT;
CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
InstructionReceptor* receptor) const override
WARN_UNUSED_RESULT;
CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
override WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool RelToRVA(Elf32_Rel rel, RVA* result) const override;
[[nodiscard]] CheckBool ParseRelocationSection(
const Elf32_Shdr* section_header,
InstructionReceptor* receptor) const override;
[[nodiscard]] CheckBool ParseRel32RelocsFromSection(
const Elf32_Shdr* section) override;
#if COURGETTE_HISTOGRAM_TARGETS
std::map<RVA, int> rel32_target_rvas_;

@ -75,20 +75,19 @@ class DisassemblerWin32 : public Disassembler {
DisassemblerWin32(const uint8_t* start, size_t length);
CheckBool ParseFile(AssemblyProgram* target,
InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseFile(AssemblyProgram* target,
InstructionReceptor* receptor) const;
virtual void ParseRel32RelocsFromSection(const Section* section) = 0;
CheckBool ParseNonSectionFileRegion(FileOffset start_file_offset,
FileOffset end_file_offset,
InstructionReceptor* receptor) const
WARN_UNUSED_RESULT;
CheckBool ParseFileRegion(const Section* section,
FileOffset start_file_offset,
FileOffset end_file_offset,
AssemblyProgram* program,
InstructionReceptor* receptor) const
WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ParseNonSectionFileRegion(
FileOffset start_file_offset,
FileOffset end_file_offset,
InstructionReceptor* receptor) const;
[[nodiscard]] CheckBool ParseFileRegion(const Section* section,
FileOffset start_file_offset,
FileOffset end_file_offset,
AssemblyProgram* program,
InstructionReceptor* receptor) const;
// Returns address width in byte count.
virtual int AbsVAWidth() const = 0;

@ -610,7 +610,7 @@ class RelocBlock {
pod.block_size += 2;
}
CheckBool Flush(SinkStream* buffer) WARN_UNUSED_RESULT {
[[nodiscard]] CheckBool Flush(SinkStream* buffer) {
bool ok = true;
if (pod.block_size != 8) {
if (pod.block_size % 4 != 0) { // Pad to make size multiple of 4 bytes.

@ -56,23 +56,22 @@ class EncodedProgram {
// (2) Address tables and indexes imported first.
CheckBool ImportLabels(const LabelManager& abs32_label_manager,
const LabelManager& rel32_label_manager)
WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool ImportLabels(const LabelManager& abs32_label_manager,
const LabelManager& rel32_label_manager);
// (3) Add instructions in the order needed to generate bytes of file.
// NOTE: If any of these methods ever fail, the EncodedProgram instance
// has failed and should be discarded.
CheckBool AddOrigin(RVA rva) WARN_UNUSED_RESULT;
CheckBool AddCopy(size_t count, const void* bytes) WARN_UNUSED_RESULT;
CheckBool AddRel32(int label_index) WARN_UNUSED_RESULT;
CheckBool AddAbs32(int label_index) WARN_UNUSED_RESULT;
CheckBool AddAbs64(int label_index) WARN_UNUSED_RESULT;
CheckBool AddPeMakeRelocs(ExecutableType kind) WARN_UNUSED_RESULT;
CheckBool AddElfMakeRelocs() WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool AddOrigin(RVA rva);
[[nodiscard]] CheckBool AddCopy(size_t count, const void* bytes);
[[nodiscard]] CheckBool AddRel32(int label_index);
[[nodiscard]] CheckBool AddAbs32(int label_index);
[[nodiscard]] CheckBool AddAbs64(int label_index);
[[nodiscard]] CheckBool AddPeMakeRelocs(ExecutableType kind);
[[nodiscard]] CheckBool AddElfMakeRelocs();
// (3) Serialize binary assembly language tables to a set of streams.
CheckBool WriteTo(SinkStreamSet* streams) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool WriteTo(SinkStreamSet* streams);
// Using an EncodedProgram to generate a byte stream:
//
@ -80,7 +79,7 @@ class EncodedProgram {
bool ReadFrom(SourceStreamSet* streams);
// (5) Assembles the 'binary assembly language' into final file.
CheckBool AssembleTo(SinkStream* buffer) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool AssembleTo(SinkStream* buffer);
// Calls |gen| to extract all instructions, which are then encoded and stored.
CheckBool GenerateInstructions(ExecutableType exe_type,
@ -122,10 +121,11 @@ class EncodedProgram {
// Helper for ImportLabels().
static void FillUnassignedRvaSlots(RvaVector* rvas);
CheckBool GeneratePeRelocations(SinkStream* buffer,
uint8_t type) WARN_UNUSED_RESULT;
CheckBool GenerateElfRelocations(Elf32_Word pending_elf_relocation_table,
SinkStream* buffer) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool GeneratePeRelocations(SinkStream* buffer,
uint8_t type);
[[nodiscard]] CheckBool GenerateElfRelocations(
Elf32_Word pending_elf_relocation_table,
SinkStream* buffer);
// Binary assembly language tables.
uint64_t image_base_ = 0;

@ -10,7 +10,6 @@
#include <stdlib.h>
#include <string.h>
#include "base/compiler_specific.h"
#include "base/files/file.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
@ -360,7 +359,7 @@ class NoThrowBuffer {
return size_ == 0;
}
CheckBool reserve(size_t size) WARN_UNUSED_RESULT {
[[nodiscard]] CheckBool reserve(size_t size) {
if (failed())
return false;
@ -386,7 +385,7 @@ class NoThrowBuffer {
return !failed();
}
CheckBool append(const T* data, size_t size) WARN_UNUSED_RESULT {
[[nodiscard]] CheckBool append(const T* data, size_t size) {
if (failed())
return false;
@ -420,7 +419,7 @@ class NoThrowBuffer {
return true;
}
CheckBool resize(size_t size, const T& init_value) WARN_UNUSED_RESULT {
[[nodiscard]] CheckBool resize(size_t size, const T& init_value) {
if (size > size_) {
if (!reserve(size))
return false;
@ -436,9 +435,7 @@ class NoThrowBuffer {
return true;
}
CheckBool push_back(const T& item) WARN_UNUSED_RESULT {
return append(&item, 1);
}
[[nodiscard]] CheckBool push_back(const T& item) { return append(&item, 1); }
const T& back() const {
return buffer_[size_ - 1];

@ -19,7 +19,6 @@
#include <stdio.h> // for FILE*
#include <string>
#include "base/compiler_specific.h"
#include "courgette/memory_allocator.h"
#include "courgette/region.h"
@ -136,21 +135,21 @@ class SinkStream {
~SinkStream() {}
// Appends |byte_count| bytes from |data| to the stream.
CheckBool Write(const void* data, size_t byte_count) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool Write(const void* data, size_t byte_count);
// Appends the 'varint32' encoding of |value| to the stream.
CheckBool WriteVarint32(uint32_t value) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool WriteVarint32(uint32_t value);
// Appends the 'varint32' encoding of |value| to the stream.
CheckBool WriteVarint32Signed(int32_t value) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool WriteVarint32Signed(int32_t value);
// Appends the 'varint32' encoding of |value| to the stream.
// On platforms where sizeof(size_t) != sizeof(int32_t), do a safety check.
CheckBool WriteSizeVarint32(size_t value) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool WriteSizeVarint32(size_t value);
// Contents of |other| are appended to |this| stream. The |other| stream
// becomes retired.
CheckBool Append(SinkStream* other) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool Append(SinkStream* other);
// Returns the number of bytes in this SinkStream
size_t Length() const { return buffer_.size(); }
@ -164,7 +163,7 @@ class SinkStream {
// Hints that the stream will grow by an additional |length| bytes.
// Caller must be prepared to handle memory allocation problems.
CheckBool Reserve(size_t length) WARN_UNUSED_RESULT {
[[nodiscard]] CheckBool Reserve(size_t length) {
return buffer_.reserve(length + buffer_.size());
}
@ -239,15 +238,15 @@ class SinkStreamSet {
// CopyTo serializes the streams in this SinkStreamSet into a single target
// stream. The serialized format may be re-read by initializing a
// SourceStreamSet with a buffer containing the data.
CheckBool CopyTo(SinkStream* combined_stream) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool CopyTo(SinkStream* combined_stream);
// Writes the streams of |set| into the corresponding streams of |this|.
// Stream zero first has some metadata written to it. |set| becomes retired.
// Partner to SourceStreamSet::ReadSet.
CheckBool WriteSet(SinkStreamSet* set) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool WriteSet(SinkStreamSet* set);
private:
CheckBool CopyHeaderTo(SinkStream* stream) WARN_UNUSED_RESULT;
[[nodiscard]] CheckBool CopyHeaderTo(SinkStream* stream);
size_t count_;
SinkStream streams_[kMaxStreams];