Restructure some assertion checking based on post commit feedback by Aaron and Tom.
authorPhilip Reames <listmail@philipreames.com>
Tue, 2 Dec 2014 21:01:48 +0000 (21:01 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 2 Dec 2014 21:01:48 +0000 (21:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223150 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Statepoint.h
lib/CodeGen/SelectionDAG/StatepointLowering.cpp

index 689f93155d711328910ffc1ad6cda4587c20a99e..035509c11e63f3f80eca6550b8215cb50ff65622 100644 (file)
@@ -129,7 +129,13 @@ class StatepointBase {
 
 
 #ifndef NDEBUG
+  /// Asserts if this statepoint is malformed.  Common cases for failure
+  /// include incorrect length prefixes for variable length sections or
+  /// illegal values for parameters.
   void verify() {
+    assert(numCallArgs() >= 0 &&
+           "number of arguments to actually callee can't be negative");
+
     // The internal asserts in the iterator accessors do the rest.
     (void)call_args_begin();
     (void)call_args_end();
index 137403fc27487280e604bca58cb48aeb5f0ab6ea..972aa9c4c8d04ad5c0fd59875ec36477c0baa0fb 100644 (file)
@@ -228,10 +228,6 @@ static SDNode *lowerCallFromStatepoint(const CallInst &CI,
              dyn_cast<IntrinsicInst>(&CI)->getIntrinsicID() &&
          "function called must be the statepoint function");
 
-  int NumCallArgs = dyn_cast<ConstantInt>(CI.getArgOperand(1))->getZExtValue();
-  assert(NumCallArgs >= 0 && "non-negative");
-  (void)NumCallArgs;
-
   ImmutableStatepoint StatepointOperands(&CI);
 
   // Lower the actual call itself - This is a bit of a hack, but we want to
@@ -240,9 +236,6 @@ static SDNode *lowerCallFromStatepoint(const CallInst &CI,
   // differently.  Hopefully, this is slightly more robust w.r.t. calling
   // convention, return values, and other function attributes.
   Value *ActualCallee = const_cast<Value *>(StatepointOperands.actualCallee());
-#ifndef NDEBUG
-  StatepointOperands.verify();
-#endif
 
   std::vector<Value *> Args;
   CallInst::const_op_iterator arg_begin = StatepointOperands.call_args_begin();
@@ -500,6 +493,13 @@ void SelectionDAGBuilder::visitStatepoint(const CallInst &CI) {
 #endif
 
   ImmutableStatepoint ISP(&CI);
+#ifndef NDEBUG
+  // If this is a malformed statepoint, report it early to simplify debugging.
+  // This should catch any IR level mistake that's made when constructing or
+  // transforming statepoints.
+  ISP.verify();
+#endif
+
 
   // Lower statepoint vmstate and gcstate arguments
   SmallVector<SDValue, 10> LoweredArgs;