Skip to content

Commit ace6d5f

Browse files
authored
[SandboxIR] Fix base class of FenceInst. Verify instructions when building a BB in debug mode. (#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.
1 parent 5495c36 commit ace6d5f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,9 +1194,7 @@ class BasicBlock : public Value {
11941194
Instruction &back() const;
11951195

11961196
#ifndef NDEBUG
1197-
void verify() const final {
1198-
assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
1199-
}
1197+
void verify() const final;
12001198
void dumpOS(raw_ostream &OS) const final;
12011199
#endif
12021200
};
@@ -1435,7 +1433,7 @@ template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
14351433
#endif
14361434
};
14371435

1438-
class FenceInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
1436+
class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {
14391437
FenceInst(llvm::FenceInst *FI, Context &Ctx)
14401438
: SingleLLVMInstructionImpl(ClassID::Fence, Opcode::Fence, FI, Ctx) {}
14411439
friend Context; // For constructor;

llvm/lib/SandboxIR/SandboxIR.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ void BasicBlock::buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB) {
31733173
Ctx.getOrCreateValue(Op);
31743174
}
31753175
}
3176-
#if !defined(NDEBUG) && defined(SBVEC_EXPENSIVE_CHECKS)
3176+
#if !defined(NDEBUG)
31773177
verify();
31783178
#endif
31793179
}
@@ -3249,4 +3249,12 @@ void BasicBlock::dumpOS(raw_ostream &OS) const {
32493249
}
32503250
}
32513251
}
3252+
3253+
void BasicBlock::verify() const {
3254+
assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
3255+
for (const auto &I : *this) {
3256+
I.verify();
3257+
}
3258+
}
3259+
32523260
#endif // NDEBUG

0 commit comments

Comments
 (0)