From a2f3e13cf4d4ea03da017caadb60e9965eaa21dc Mon Sep 17 00:00:00 2001 From: Gordon Henriksen Date: Mon, 17 Sep 2007 20:30:04 +0000 Subject: Fix for PR1633: Verifier doesn't fully verify GC intrinsics LLVM now enforces the following prototypes for the write barriers: * @llvm.gcread(*, **) void @llvm.gcwrite(*, *, **) And for @llvm.gcroot, the first stack slot is verified to be an alloca or a bitcast of an alloca. Fixes test/CodeGen/Generic/GC/lower_gcroot.ll, which violated these. llvm-svn: 42051 --- llvm/lib/VMCore/Verifier.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'llvm/lib/VMCore/Verifier.cpp') diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 58bf485512a..25826e106cb 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -1072,6 +1072,18 @@ void Verifier::visitInstruction(Instruction &I) { InstsInThisBlock.insert(&I); } +static bool HasPtrPtrType(Value *Val) { + if (const PointerType *PtrTy = dyn_cast(Val->getType())) + return isa(PtrTy->getElementType()); + return false; +} + +static Value *StripBitCasts(Value *Val) { + if (BitCastInst *CI = dyn_cast(Val)) + return StripBitCasts(CI->getOperand(0)); + return Val; +} + /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways. /// void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { @@ -1082,6 +1094,30 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { #define GET_INTRINSIC_VERIFIER #include "llvm/Intrinsics.gen" #undef GET_INTRINSIC_VERIFIER + + switch (ID) { + default: + break; + case Intrinsic::gcroot: + Assert1(HasPtrPtrType(CI.getOperand(1)), + "llvm.gcroot parameter #1 must be a pointer to a pointer.", &CI); + Assert1(isa(StripBitCasts(CI.getOperand(1))), + "llvm.gcroot parameter #1 must be an alloca (or a bitcast).", &CI); + Assert1(isa(CI.getOperand(2)), + "llvm.gcroot parameter #2 must be a constant or global.", &CI); + break; + case Intrinsic::gcwrite: + Assert1(CI.getOperand(3)->getType() + == PointerType::get(CI.getOperand(1)->getType()), + "Call to llvm.gcwrite must be with type 'void (%ty*, %ty2*, %ty**)'.", + &CI); + break; + case Intrinsic::gcread: + Assert1(CI.getOperand(2)->getType() == PointerType::get(CI.getType()), + "Call to llvm.gcread must be with type '%ty* (%ty2*, %ty**).'", + &CI); + break; + } } /// VerifyIntrinsicPrototype - TableGen emits calls to this function into -- cgit v1.2.3