[llvm] 3cf1018 - [SandboxIR] Add test that checks if classof() is missing. (#106313)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 11:34:31 PDT 2024
Author: vporpo
Date: 2024-08-28T11:34:26-07:00
New Revision: 3cf1018f4c66ecd1f98fa6c90c2c4167efc6c9dc
URL: https://github.com/llvm/llvm-project/commit/3cf1018f4c66ecd1f98fa6c90c2c4167efc6c9dc
DIFF: https://github.com/llvm/llvm-project/commit/3cf1018f4c66ecd1f98fa6c90c2c4167efc6c9dc.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/SandboxIR/SandboxIR.h
llvm/unittests/SandboxIR/SandboxIRTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 9818a8bcbc2cb4..14210ae35c0082 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 016024750baf21..31519074e1b908 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"
+}
More information about the llvm-commits
mailing list