Skip to content

Commit 3cf1018

Browse files
authored
[SandboxIR] Add test that checks if classof() is missing. (#106313)
Forgetting to implement an `<Instruction Subclass>::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.
1 parent efbafbc commit 3cf1018

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,10 @@ class AtomicCmpXchgInst
27442744
AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
27452745
BasicBlock *InsertAtEnd, Context &Ctx,
27462746
SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2747+
2748+
static bool classof(const Value *From) {
2749+
return From->getSubclassID() == ClassID::AtomicCmpXchg;
2750+
}
27472751
};
27482752

27492753
class AllocaInst final : public UnaryInstruction {

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4317,3 +4317,10 @@ define void @foo() {
43174317
EXPECT_EQ(NewUIEnd->getParent(), BB);
43184318
EXPECT_EQ(NewUIEnd->getNextNode(), nullptr);
43194319
}
4320+
4321+
/// Makes sure that all Instruction sub-classes have a classof().
4322+
TEST_F(SandboxIRTest, CheckClassof) {
4323+
#define DEF_INSTR(ID, OPC, CLASS) \
4324+
EXPECT_NE(&sandboxir::CLASS::classof, &sandboxir::Instruction::classof);
4325+
#include "llvm/SandboxIR/SandboxIRValues.def"
4326+
}

0 commit comments

Comments
 (0)