From 29d2d35602c200eae4c5b142142772e3cc042267 Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas Date: Tue, 27 Aug 2024 16:44:01 -0700 Subject: [PATCH] [SandboxIR] Add test that checks if classof is missing. Forgetting to implement an `::classof()` function does not cause any failures because it falls back to Instruction::classof(). This patch adds an explicit check for all instruction classes to confirm that they have a classof implementation. --- llvm/include/llvm/SandboxIR/SandboxIR.h | 4 ++++ llvm/unittests/SandboxIR/SandboxIRTest.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h index 9818a8bcbc2cb..14210ae35c008 100644 --- a/llvm/include/llvm/SandboxIR/SandboxIR.h +++ b/llvm/include/llvm/SandboxIR/SandboxIR.h @@ -2744,6 +2744,10 @@ class AtomicCmpXchgInst AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, BasicBlock *InsertAtEnd, Context &Ctx, SyncScope::ID SSID = SyncScope::System, const Twine &Name = ""); + + static bool classof(const Value *From) { + return From->getSubclassID() == ClassID::AtomicCmpXchg; + } }; class AllocaInst final : public UnaryInstruction { diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 016024750baf2..31519074e1b90 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -4317,3 +4317,10 @@ define void @foo() { EXPECT_EQ(NewUIEnd->getParent(), BB); EXPECT_EQ(NewUIEnd->getNextNode(), nullptr); } + +/// Makes sure that all Instruction sub-classes have a classof(). +TEST_F(SandboxIRTest, CheckClassof) { +#define DEF_INSTR(ID, OPC, CLASS) \ + EXPECT_NE(&sandboxir::CLASS::classof, &sandboxir::Instruction::classof); +#include "llvm/SandboxIR/SandboxIRValues.def" +}