Skip to content

Commit

Permalink
[NFC] Add 'override' keyword where missing in include/ and lib/.
Browse files Browse the repository at this point in the history
This fixes warnings raised by Clang's new -Wsuggest-override, in preparation for enabling that warning in the LLVM build. This patch also removes the virtual keyword where redundant, but only in places where doing so improves consistency within a given file. It also removes a couple unnecessary virtual destructor declarations in derived classes where the destructor inherited from the base class is already virtual.

Differential Revision: https://reviews.llvm.org/D83709
  • Loading branch information
kepler-5 committed Jul 14, 2020
1 parent fbb30c3 commit a19461d
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 111 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/InstructionPrecedenceTracking.h
Expand Up @@ -110,7 +110,7 @@ class ImplicitControlFlowTracking : public InstructionPrecedenceTracking {
return isPreceededBySpecialInstruction(Insn);
}

virtual bool isSpecialInstruction(const Instruction *Insn) const;
bool isSpecialInstruction(const Instruction *Insn) const override;
};

class MemoryWriteTracking : public InstructionPrecedenceTracking {
Expand All @@ -133,7 +133,7 @@ class MemoryWriteTracking : public InstructionPrecedenceTracking {
return isPreceededBySpecialInstruction(Insn);
}

virtual bool isSpecialInstruction(const Instruction *Insn) const;
bool isSpecialInstruction(const Instruction *Insn) const override;
};

} // llvm
Expand Down
28 changes: 12 additions & 16 deletions llvm/include/llvm/Analysis/MustExecute.h
Expand Up @@ -111,17 +111,15 @@ class SimpleLoopSafetyInfo: public LoopSafetyInfo {
bool HeaderMayThrow = false; // Same as previous, but specific to loop header

public:
virtual bool blockMayThrow(const BasicBlock *BB) const;
bool blockMayThrow(const BasicBlock *BB) const override;

virtual bool anyBlockMayThrow() const;
bool anyBlockMayThrow() const override;

virtual void computeLoopSafetyInfo(const Loop *CurLoop);
void computeLoopSafetyInfo(const Loop *CurLoop) override;

virtual bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop) const;

virtual ~SimpleLoopSafetyInfo() {};
bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop) const override;
};

/// This implementation of LoopSafetyInfo use ImplicitControlFlowTracking to
Expand All @@ -138,15 +136,15 @@ class ICFLoopSafetyInfo: public LoopSafetyInfo {
mutable MemoryWriteTracking MW;

public:
virtual bool blockMayThrow(const BasicBlock *BB) const;
bool blockMayThrow(const BasicBlock *BB) const override;

virtual bool anyBlockMayThrow() const;
bool anyBlockMayThrow() const override;

virtual void computeLoopSafetyInfo(const Loop *CurLoop);
void computeLoopSafetyInfo(const Loop *CurLoop) override;

virtual bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop) const;
bool isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT,
const Loop *CurLoop) const override;

/// Returns true if we could not execute a memory-modifying instruction before
/// we enter \p BB under assumption that \p CurLoop is entered.
Expand All @@ -167,8 +165,6 @@ class ICFLoopSafetyInfo: public LoopSafetyInfo {
/// from its block. It will make all cache updates to keep it correct after
/// this removal.
void removeInstruction(const Instruction *Inst);

virtual ~ICFLoopSafetyInfo() {};
};

bool mayContainIrreducibleControl(const Function &F, const LoopInfo *LI);
Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
Expand Up @@ -313,8 +313,8 @@ struct PrimitiveTypeNode : public TypeNode {
explicit PrimitiveTypeNode(PrimitiveKind K)
: TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}

void outputPre(OutputStream &OS, OutputFlags Flags) const;
void outputPost(OutputStream &OS, OutputFlags Flags) const {}
void outputPre(OutputStream &OS, OutputFlags Flags) const override;
void outputPost(OutputStream &OS, OutputFlags Flags) const override {}

PrimitiveKind PrimKind;
};
Expand Down Expand Up @@ -474,8 +474,8 @@ struct PointerTypeNode : public TypeNode {
struct TagTypeNode : public TypeNode {
explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}

void outputPre(OutputStream &OS, OutputFlags Flags) const;
void outputPost(OutputStream &OS, OutputFlags Flags) const;
void outputPre(OutputStream &OS, OutputFlags Flags) const override;
void outputPost(OutputStream &OS, OutputFlags Flags) const override;

QualifiedNameNode *QualifiedName = nullptr;
TagKind Tag;
Expand All @@ -484,8 +484,8 @@ struct TagTypeNode : public TypeNode {
struct ArrayTypeNode : public TypeNode {
ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {}

void outputPre(OutputStream &OS, OutputFlags Flags) const;
void outputPost(OutputStream &OS, OutputFlags Flags) const;
void outputPre(OutputStream &OS, OutputFlags Flags) const override;
void outputPost(OutputStream &OS, OutputFlags Flags) const override;

void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const;
void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const;
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/IR/DiagnosticInfo.h
Expand Up @@ -213,7 +213,7 @@ class DiagnosticInfoResourceLimit : public DiagnosticInfo {
};

class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
virtual void anchor() override;
void anchor() override;
public:
DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
DiagnosticSeverity Severity = DS_Warning,
Expand Down Expand Up @@ -364,7 +364,7 @@ class DiagnosticLocation {

/// Common features for diagnostics with an associated location.
class DiagnosticInfoWithLocationBase : public DiagnosticInfo {
virtual void anchor() override;
void anchor() override;
public:
/// \p Fn is the function where the diagnostic is being emitted. \p Loc is
/// the location information to use in the diagnostic.
Expand Down Expand Up @@ -611,7 +611,7 @@ operator<<(RemarkT &R,
/// Common features for diagnostics dealing with optimization remarks
/// that are used by IR passes.
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
virtual void anchor() override;
void anchor() override;
public:
/// \p PassName is the name of the pass emitting this diagnostic. \p
/// RemarkName is a textual identifier for the remark (single-word,
Expand Down Expand Up @@ -832,7 +832,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
/// Diagnostic information for optimization analysis remarks related to
/// floating-point non-commutativity.
class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
virtual void anchor();
void anchor() override;
public:
/// \p PassName is the name of the pass emitting this diagnostic. If this name
/// matches the regular expression given in -Rpass-analysis=, then the
Expand Down Expand Up @@ -874,7 +874,7 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
/// Diagnostic information for optimization analysis remarks related to
/// pointer aliasing.
class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
virtual void anchor();
void anchor() override;
public:
/// \p PassName is the name of the pass emitting this diagnostic. If this name
/// matches the regular expression given in -Rpass-analysis=, then the
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCELFObjectWriter.h
Expand Up @@ -65,7 +65,7 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
public:
virtual ~MCELFObjectTargetWriter() = default;

virtual Triple::ObjectFormatType getFormat() const { return Triple::ELF; }
Triple::ObjectFormatType getFormat() const override { return Triple::ELF; }
static bool classof(const MCObjectTargetWriter *W) {
return W->getFormat() == Triple::ELF;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCMachObjectWriter.h
Expand Up @@ -45,7 +45,7 @@ class MCMachObjectTargetWriter : public MCObjectTargetWriter {
public:
virtual ~MCMachObjectTargetWriter();

virtual Triple::ObjectFormatType getFormat() const { return Triple::MachO; }
Triple::ObjectFormatType getFormat() const override { return Triple::MachO; }
static bool classof(const MCObjectTargetWriter *W) {
return W->getFormat() == Triple::MachO;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCWasmObjectWriter.h
Expand Up @@ -28,7 +28,7 @@ class MCWasmObjectTargetWriter : public MCObjectTargetWriter {
public:
virtual ~MCWasmObjectTargetWriter();

virtual Triple::ObjectFormatType getFormat() const { return Triple::Wasm; }
Triple::ObjectFormatType getFormat() const override { return Triple::Wasm; }
static bool classof(const MCObjectTargetWriter *W) {
return W->getFormat() == Triple::Wasm;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
Expand Up @@ -31,7 +31,7 @@ class raw_pwrite_stream;
public:
virtual ~MCWinCOFFObjectTargetWriter() = default;

virtual Triple::ObjectFormatType getFormat() const { return Triple::COFF; }
Triple::ObjectFormatType getFormat() const override { return Triple::COFF; }
static bool classof(const MCObjectTargetWriter *W) {
return W->getFormat() == Triple::COFF;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/Error.h
Expand Up @@ -51,7 +51,7 @@ inline std::error_code make_error_code(object_error e) {
/// Currently inherits from ECError for easy interoperability with
/// std::error_code, but this will be removed in the future.
class BinaryError : public ErrorInfo<BinaryError, ECError> {
virtual void anchor();
void anchor() override;
public:
static char ID;
BinaryError() {
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/Support/FormatAdapters.h
Expand Up @@ -34,7 +34,7 @@ template <typename T> class AlignAdapter final : public FormatAdapter<T> {
: FormatAdapter<T>(std::forward<T>(Item)), Where(Where), Amount(Amount),
Fill(Fill) {}

void format(llvm::raw_ostream &Stream, StringRef Style) {
void format(llvm::raw_ostream &Stream, StringRef Style) override {
auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
FmtAlign(Adapter, Where, Amount, Fill).format(Stream, Style);
}
Expand All @@ -48,7 +48,7 @@ template <typename T> class PadAdapter final : public FormatAdapter<T> {
PadAdapter(T &&Item, size_t Left, size_t Right)
: FormatAdapter<T>(std::forward<T>(Item)), Left(Left), Right(Right) {}

void format(llvm::raw_ostream &Stream, StringRef Style) {
void format(llvm::raw_ostream &Stream, StringRef Style) override {
auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
Stream.indent(Left);
Adapter.format(Stream, Style);
Expand All @@ -63,7 +63,7 @@ template <typename T> class RepeatAdapter final : public FormatAdapter<T> {
RepeatAdapter(T &&Item, size_t Count)
: FormatAdapter<T>(std::forward<T>(Item)), Count(Count) {}

void format(llvm::raw_ostream &Stream, StringRef Style) {
void format(llvm::raw_ostream &Stream, StringRef Style) override {
auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
for (size_t I = 0; I < Count; ++I) {
Adapter.format(Stream, Style);
Expand All @@ -76,7 +76,9 @@ class ErrorAdapter : public FormatAdapter<Error> {
ErrorAdapter(Error &&Item) : FormatAdapter(std::move(Item)) {}
ErrorAdapter(ErrorAdapter &&) = default;
~ErrorAdapter() { consumeError(std::move(Item)); }
void format(llvm::raw_ostream &Stream, StringRef Style) { Stream << Item; }
void format(llvm::raw_ostream &Stream, StringRef Style) override {
Stream << Item;
}
};
}

Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Expand Up @@ -330,11 +330,11 @@ class LazyValueInfoAnnotatedWriter : public AssemblyAnnotationWriter {
LazyValueInfoAnnotatedWriter(LazyValueInfoImpl *L, DominatorTree &DTree)
: LVIImpl(L), DT(DTree) {}

virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
formatted_raw_ostream &OS);
void emitBasicBlockStartAnnot(const BasicBlock *BB,
formatted_raw_ostream &OS) override;

virtual void emitInstructionAnnot(const Instruction *I,
formatted_raw_ostream &OS);
void emitInstructionAnnot(const Instruction *I,
formatted_raw_ostream &OS) override;
};
}
namespace {
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Expand Up @@ -101,21 +101,21 @@ class CVMCAdapter : public CodeViewRecordStreamer {
CVMCAdapter(MCStreamer &OS, TypeCollection &TypeTable)
: OS(&OS), TypeTable(TypeTable) {}

void emitBytes(StringRef Data) { OS->emitBytes(Data); }
void emitBytes(StringRef Data) override { OS->emitBytes(Data); }

void emitIntValue(uint64_t Value, unsigned Size) {
void emitIntValue(uint64_t Value, unsigned Size) override {
OS->emitIntValueInHex(Value, Size);
}

void emitBinaryData(StringRef Data) { OS->emitBinaryData(Data); }
void emitBinaryData(StringRef Data) override { OS->emitBinaryData(Data); }

void AddComment(const Twine &T) { OS->AddComment(T); }
void AddComment(const Twine &T) override { OS->AddComment(T); }

void AddRawComment(const Twine &T) { OS->emitRawComment(T); }
void AddRawComment(const Twine &T) override { OS->emitRawComment(T); }

bool isVerboseAsm() { return OS->isVerboseAsm(); }
bool isVerboseAsm() override { return OS->isVerboseAsm(); }

std::string getTypeName(TypeIndex TI) {
std::string getTypeName(TypeIndex TI) override {
std::string TypeName;
if (!TI.isNoneType()) {
if (TI.isSimple())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/MCTargetDesc/R600MCCodeEmitter.cpp
Expand Up @@ -47,7 +47,7 @@ class R600MCCodeEmitter : public MCCodeEmitter {
/// Encode the instruction and write it to the OS.
void encodeInstruction(const MCInst &MI, raw_ostream &OS,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
const MCSubtargetInfo &STI) const override;

/// \returns the encoding for an MCOperand.
uint64_t getMachineOpValue(const MCInst &MI, const MCOperand &MO,
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AVR/AVRFrameLowering.cpp
Expand Up @@ -405,7 +405,7 @@ struct AVRFrameAnalyzer : public MachineFunctionPass {
static char ID;
AVRFrameAnalyzer() : MachineFunctionPass(ID) {}

bool runOnMachineFunction(MachineFunction &MF) {
bool runOnMachineFunction(MachineFunction &MF) override {
const MachineFrameInfo &MFI = MF.getFrameInfo();
AVRMachineFunctionInfo *FuncInfo = MF.getInfo<AVRMachineFunctionInfo>();

Expand Down Expand Up @@ -457,7 +457,7 @@ struct AVRFrameAnalyzer : public MachineFunctionPass {
return false;
}

StringRef getPassName() const { return "AVR Frame Analyzer"; }
StringRef getPassName() const override { return "AVR Frame Analyzer"; }
};

char AVRFrameAnalyzer::ID = 0;
Expand All @@ -473,7 +473,7 @@ struct AVRDynAllocaSR : public MachineFunctionPass {
static char ID;
AVRDynAllocaSR() : MachineFunctionPass(ID) {}

bool runOnMachineFunction(MachineFunction &MF) {
bool runOnMachineFunction(MachineFunction &MF) override {
// Early exit when there are no variable sized objects in the function.
if (!MF.getFrameInfo().hasVarSizedObjects()) {
return false;
Expand Down Expand Up @@ -506,7 +506,7 @@ struct AVRDynAllocaSR : public MachineFunctionPass {
return true;
}

StringRef getPassName() const {
StringRef getPassName() const override {
return "AVR dynalloca stack pointer save/restore";
}
};
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp
Expand Up @@ -178,18 +178,18 @@ class AVROperand : public MCParsedAsmOperand {
return isUInt<8>(Value);
}

bool isReg() const { return Kind == k_Register; }
bool isImm() const { return Kind == k_Immediate; }
bool isToken() const { return Kind == k_Token; }
bool isMem() const { return Kind == k_Memri; }
bool isReg() const override { return Kind == k_Register; }
bool isImm() const override { return Kind == k_Immediate; }
bool isToken() const override { return Kind == k_Token; }
bool isMem() const override { return Kind == k_Memri; }
bool isMemri() const { return Kind == k_Memri; }

StringRef getToken() const {
assert(Kind == k_Token && "Invalid access!");
return Tok;
}

unsigned getReg() const {
unsigned getReg() const override {
assert((Kind == k_Register || Kind == k_Memri) && "Invalid access!");

return RegImm.Reg;
Expand Down Expand Up @@ -239,10 +239,10 @@ class AVROperand : public MCParsedAsmOperand {
RegImm = {RegNo, Imm};
}

SMLoc getStartLoc() const { return Start; }
SMLoc getEndLoc() const { return End; }
SMLoc getStartLoc() const override { return Start; }
SMLoc getEndLoc() const override { return End; }

virtual void print(raw_ostream &O) const {
void print(raw_ostream &O) const override {
switch (Kind) {
case k_Token:
O << "Token: \"" << getToken() << "\"";
Expand Down

0 comments on commit a19461d

Please sign in to comment.