[llvm] [SandboxIR] Fix base class of FenceInst. Verify instructions when building a BB in debug mode. (PR #108078)
Jorge Gorbe Moya via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 13:10:14 PDT 2024
https://github.com/slackito created https://github.com/llvm/llvm-project/pull/108078
@vporpo suggested in an offline conversation that verifying all instructions during `BasicBlock::buildBasicBlockFromLLVMIR` would be a good way to get coverage for errors like this during testing. He also suggested not gating it on `SBVEC_EXPENSIVE_CHECKS` for now as the checks are pretty basic at the moment and they only affect Debug builds.
>From b4924799d3b63c7815b9417fc14b4350f2261415 Mon Sep 17 00:00:00 2001
From: Jorge Gorbe Moya <jgorbe at google.com>
Date: Mon, 9 Sep 2024 17:58:27 -0700
Subject: [PATCH] [SandboxIR] Fix base class of FenceInst. Verify instructions
when creating a BB in debug mode.
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 6 ++----
llvm/lib/SandboxIR/SandboxIR.cpp | 10 +++++++++-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 8f025f7257b39f..91d6b58cfee00c 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -1194,9 +1194,7 @@ class BasicBlock : public Value {
Instruction &back() const;
#ifndef NDEBUG
- void verify() const final {
- assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
- }
+ void verify() const final;
void dumpOS(raw_ostream &OS) const final;
#endif
};
@@ -1435,7 +1433,7 @@ template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
#endif
};
-class FenceInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
+class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {
FenceInst(llvm::FenceInst *FI, Context &Ctx)
: SingleLLVMInstructionImpl(ClassID::Fence, Opcode::Fence, FI, Ctx) {}
friend Context; // For constructor;
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 07472d1bff47be..a4b68bd8ffd7c9 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -3173,7 +3173,7 @@ void BasicBlock::buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB) {
Ctx.getOrCreateValue(Op);
}
}
-#if !defined(NDEBUG) && defined(SBVEC_EXPENSIVE_CHECKS)
+#if !defined(NDEBUG)
verify();
#endif
}
@@ -3249,4 +3249,12 @@ void BasicBlock::dumpOS(raw_ostream &OS) const {
}
}
}
+
+void BasicBlock::verify() const {
+ assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
+ for (const auto &I : *this) {
+ I.verify();
+ }
+}
+
#endif // NDEBUG
More information about the llvm-commits
mailing list