summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2015-01-07 22:48:01 +0000
committerPhilip Reames <listmail@philipreames.com>2015-01-07 22:48:01 +0000
commit76ebd154376ede49df82f22809bd7b113096b96c (patch)
tree28bbe49dc631066475c7fd5acd2157c44b9bb3ae /llvm/lib/IR/Verifier.cpp
parent97fea8bb95ed75c745e62d3f89035ff7e721caae (diff)
downloadbcm5719-llvm-76ebd154376ede49df82f22809bd7b113096b96c.tar.gz
bcm5719-llvm-76ebd154376ede49df82f22809bd7b113096b96c.zip
[GC] improve testing around gc.relocate and fix a test
Patch by: Ramkumar Ramachandra <artagnon@gmail.com> "This patch started out as an exploration of gc.relocate, and an attempt to write a simple test in call-lowering. I then noticed that the arguments of gc.relocate were not checked fully, so I went in and fixed a few things. Finally, the most important outcome of this patch is that my new error handling code caught a bug in a callsite in stackmap-format." Differential Revision: http://reviews.llvm.org/D6824 llvm-svn: 225412
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index bc721145d2a..ad7473b6611 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2691,10 +2691,12 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
case Intrinsic::experimental_gc_result_ptr: {
// Are we tied to a statepoint properly?
CallSite StatepointCS(CI.getArgOperand(0));
- const Function *StatepointFn = StatepointCS.getCalledFunction();
+ const Function *StatepointFn =
+ StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : nullptr;
Assert2(StatepointFn && StatepointFn->isDeclaration() &&
StatepointFn->getIntrinsicID() == Intrinsic::experimental_gc_statepoint,
- "token must be from a statepoint", &CI, CI.getArgOperand(0));
+ "gc.result operand #1 must be from a statepoint",
+ &CI, CI.getArgOperand(0));
// Assert that result type matches wrapped callee.
const Value *Target = StatepointCS.getArgument(0);
@@ -2710,32 +2712,53 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
// Are we tied to a statepoint properly?
CallSite StatepointCS(CI.getArgOperand(0));
const Function *StatepointFn =
- StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : NULL;
+ StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : nullptr;
Assert2(StatepointFn && StatepointFn->isDeclaration() &&
StatepointFn->getIntrinsicID() == Intrinsic::experimental_gc_statepoint,
- "token must be from a statepoint", &CI, CI.getArgOperand(0));
+ "gc.relocate operand #1 must be from a statepoint",
+ &CI, CI.getArgOperand(0));
// Both the base and derived must be piped through the safepoint
Value* Base = CI.getArgOperand(1);
- Assert1( isa<ConstantInt>(Base), "must be integer offset", &CI);
+ Assert1(isa<ConstantInt>(Base),
+ "gc.relocate operand #2 must be integer offset", &CI);
Value* Derived = CI.getArgOperand(2);
- Assert1( isa<ConstantInt>(Derived), "must be integer offset", &CI);
+ Assert1(isa<ConstantInt>(Derived),
+ "gc.relocate operand #3 must be integer offset", &CI);
const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
// Check the bounds
Assert1(0 <= BaseIndex &&
BaseIndex < (int)StatepointCS.arg_size(),
- "index out of bounds", &CI);
+ "gc.relocate: statepoint base index out of bounds", &CI);
Assert1(0 <= DerivedIndex &&
DerivedIndex < (int)StatepointCS.arg_size(),
- "index out of bounds", &CI);
+ "gc.relocate: statepoint derived index out of bounds", &CI);
+
+ // Check that BaseIndex and DerivedIndex fall within the 'gc parameters'
+ // section of the statepoint's argument
+ const int NumCallArgs =
+ cast<ConstantInt>(StatepointCS.getArgument(1))->getZExtValue();
+ const int NumDeoptArgs =
+ cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 3))->getZExtValue();
+ const int GCParamArgsStart = NumCallArgs + NumDeoptArgs + 4;
+ const int GCParamArgsEnd = StatepointCS.arg_size();
+ Assert1(GCParamArgsStart <= BaseIndex &&
+ BaseIndex < GCParamArgsEnd,
+ "gc.relocate: statepoint base index doesn't fall within the "
+ "'gc parameters' section of the statepoint call", &CI);
+ Assert1(GCParamArgsStart <= DerivedIndex &&
+ DerivedIndex < GCParamArgsEnd,
+ "gc.relocate: statepoint derived index doesn't fall within the "
+ "'gc parameters' section of the statepoint call", &CI);
+
// Assert that the result type matches the type of the relocated pointer
GCRelocateOperands Operands(&CI);
Assert1(Operands.derivedPtr()->getType() == CI.getType(),
- "gc.relocate: relocating a pointer shouldn't change it's type",
+ "gc.relocate: relocating a pointer shouldn't change its type",
&CI);
break;
}
OpenPOWER on IntegriCloud