[llvm] ace6d5f - [SandboxIR] Fix base class of FenceInst. Verify instructions when building a BB in debug mode. (#108078)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 14:33:07 PDT 2024


Author: Jorge Gorbe Moya
Date: 2024-09-10T14:33:04-07:00
New Revision: ace6d5f2ce53ae88205fc39dafa45e5682fd9a52

URL: https://github.com/llvm/llvm-project/commit/ace6d5f2ce53ae88205fc39dafa45e5682fd9a52
DIFF: https://github.com/llvm/llvm-project/commit/ace6d5f2ce53ae88205fc39dafa45e5682fd9a52.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/SandboxIR/SandboxIR.h
    llvm/lib/SandboxIR/SandboxIR.cpp

Removed: 
    


################################################################################
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