[llvm] c0e8c94 - [DomTree] Make assert more precise

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 13:41:55 PDT 2020


Author: Nikita Popov
Date: 2020-10-22T22:40:06+02:00
New Revision: c0e8c94373b4e97d2eecc53bb16d22e085b73948

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

LOG: [DomTree] Make assert more precise

Per asbirlea's comment, assert that only instructions, constants
and arguments are passed to this API. Simplify returning true
would not be correct for special Value subclasses like MemoryAccess.

Added: 
    

Modified: 
    llvm/lib/IR/Dominators.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp
index 0fd05549254c..fbc28c202aec 100644
--- a/llvm/lib/IR/Dominators.cpp
+++ b/llvm/lib/IR/Dominators.cpp
@@ -119,8 +119,9 @@ bool DominatorTree::dominates(const Value *DefV,
                               const Instruction *User) const {
   const Instruction *Def = dyn_cast<Instruction>(DefV);
   if (!Def) {
-    assert(!isa<BasicBlock>(DefV) && "Should not be called with basic blocks");
-    return true; // Arguments, constants, globals dominate everything.
+    assert((isa<Argument>(DefV) || isa<Constant>(DefV)) &&
+           "Should be called with an instruction, argument or constant");
+    return true; // Arguments and constants dominate everything.
   }
 
   const BasicBlock *UseBB = User->getParent();
@@ -259,8 +260,9 @@ bool DominatorTree::dominates(const BasicBlockEdge &BBE, const Use &U) const {
 bool DominatorTree::dominates(const Value *DefV, const Use &U) const {
   const Instruction *Def = dyn_cast<Instruction>(DefV);
   if (!Def) {
-    assert(!isa<BasicBlock>(DefV) && "Should not be called with basic blocks");
-    return true; // Arguments, constants, globals dominate everything.
+    assert((isa<Argument>(DefV) || isa<Constant>(DefV)) &&
+           "Should be called with an instruction, argument or constant");
+    return true; // Arguments and constants dominate everything.
   }
 
   Instruction *UserInst = cast<Instruction>(U.getUser());


        


More information about the llvm-commits mailing list