From 72fbe7a6f0af0390e1bb6fb1f3229c4b1ffdaaf5 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 2 Dec 2014 21:01:48 +0000 Subject: [PATCH] Restructure some assertion checking based on post commit feedback by Aaron and Tom. llvm-svn: 223150 --- llvm/include/llvm/IR/Statepoint.h | 6 ++++++ llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/IR/Statepoint.h b/llvm/include/llvm/IR/Statepoint.h index 689f931..035509c 100644 --- a/llvm/include/llvm/IR/Statepoint.h +++ b/llvm/include/llvm/IR/Statepoint.h @@ -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(); diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp index 137403f..972aa9c 100644 --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -228,10 +228,6 @@ static SDNode *lowerCallFromStatepoint(const CallInst &CI, dyn_cast(&CI)->getIntrinsicID() && "function called must be the statepoint function"); - int NumCallArgs = dyn_cast(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(StatepointOperands.actualCallee()); -#ifndef NDEBUG - StatepointOperands.verify(); -#endif std::vector 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 LoweredArgs; -- 2.7.4