llvm.org GIT mirror llvm / 982139f
[Verifier] Follow on to 240836 Address one missed review comment and do the rename I left out of that patch to make it reviewable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240843 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 4 years ago
2 changed file(s) with 83 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
196196 CALLSITE_DELEGATE_GETTER(getNumArgOperands());
197197 }
198198
199 Value *getArgOperand(unsigned i) const {
199 ValTy *getArgOperand(unsigned i) const {
200200 CALLSITE_DELEGATE_GETTER(getArgOperand(i));
201201 }
202202
101101 OS << '\n';
102102 }
103103 }
104 void Write(const CallSite *CS) {
105 if (!CS)
106 return;
107 Write(CS->getInstruction());
104 void Write(ImmutableCallSite CS) {
105 Write(CS.getInstruction());
108106 }
109107
110108 void Write(const Metadata *MD) {
31433141
31443142 /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways.
31453143 ///
3146 void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallSite CI) {
3147 Function *IF = CI.getCalledFunction();
3144 void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallSite CS) {
3145 Function *IF = CS.getCalledFunction();
31483146 Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!",
31493147 IF);
31503148
31883186
31893187 // If the intrinsic takes MDNode arguments, verify that they are either global
31903188 // or are local to *this* function.
3191 for (unsigned i = 0, e = CI.getNumArgOperands(); i != e; ++i)
3192 if (auto *MD = dyn_cast(CI.getArgOperand(i)))
3193 visitMetadataAsValue(*MD, CI.getParent()->getParent());
3189 for (unsigned i = 0, e = CS.getNumArgOperands(); i != e; ++i)
3190 if (auto *MD = dyn_cast(CS.getArgOperand(i)))
3191 visitMetadataAsValue(*MD, CS.getParent()->getParent());
31943192
31953193 switch (ID) {
31963194 default:
31973195 break;
31983196 case Intrinsic::ctlz: // llvm.ctlz
31993197 case Intrinsic::cttz: // llvm.cttz
3200 Assert(isa(CI.getArgOperand(1)),
3198 Assert(isa(CS.getArgOperand(1)),
32013199 "is_zero_undef argument of bit counting intrinsics must be a "
32023200 "constant int",
3203 &CI);
3201 CS);
32043202 break;
32053203 case Intrinsic::dbg_declare: // llvm.dbg.declare
3206 Assert(isa(CI.getArgOperand(0)),
3207 "invalid llvm.dbg.declare intrinsic call 1", &CI);
3208 visitDbgIntrinsic("declare", cast(*CI.getInstruction()));
3204 Assert(isa(CS.getArgOperand(0)),
3205 "invalid llvm.dbg.declare intrinsic call 1", CS);
3206 visitDbgIntrinsic("declare", cast(*CS.getInstruction()));
32093207 break;
32103208 case Intrinsic::dbg_value: // llvm.dbg.value
3211 visitDbgIntrinsic("value", cast(*CI.getInstruction()));
3209 visitDbgIntrinsic("value", cast(*CS.getInstruction()));
32123210 break;
32133211 case Intrinsic::memcpy:
32143212 case Intrinsic::memmove:
32153213 case Intrinsic::memset: {
3216 ConstantInt *AlignCI = dyn_cast(CI.getArgOperand(3));
3214 ConstantInt *AlignCI = dyn_cast(CS.getArgOperand(3));
32173215 Assert(AlignCI,
32183216 "alignment argument of memory intrinsics must be a constant int",
3219 &CI);
3217 CS);
32203218 const APInt &AlignVal = AlignCI->getValue();
32213219 Assert(AlignCI->isZero() || AlignVal.isPowerOf2(),
3222 "alignment argument of memory intrinsics must be a power of 2", &CI);
3223 Assert(isa(CI.getArgOperand(4)),
3220 "alignment argument of memory intrinsics must be a power of 2", CS);
3221 Assert(isa(CS.getArgOperand(4)),
32243222 "isvolatile argument of memory intrinsics must be a constant int",
3225 &CI);
3223 CS);
32263224 break;
32273225 }
32283226 case Intrinsic::gcroot:
32303228 case Intrinsic::gcread:
32313229 if (ID == Intrinsic::gcroot) {
32323230 AllocaInst *AI =
3233 dyn_cast(CI.getArgOperand(0)->stripPointerCasts());
3234 Assert(AI, "llvm.gcroot parameter #1 must be an alloca.", &CI);
3235 Assert(isa(CI.getArgOperand(1)),
3236 "llvm.gcroot parameter #2 must be a constant.", &CI);
3231 dyn_cast(CS.getArgOperand(0)->stripPointerCasts());
3232 Assert(AI, "llvm.gcroot parameter #1 must be an alloca.", CS);
3233 Assert(isa(CS.getArgOperand(1)),
3234 "llvm.gcroot parameter #2 must be a constant.", CS);
32373235 if (!AI->getAllocatedType()->isPointerTy()) {
3238 Assert(!isa(CI.getArgOperand(1)),
3236 Assert(!isa(CS.getArgOperand(1)),
32393237 "llvm.gcroot parameter #1 must either be a pointer alloca, "
32403238 "or argument #2 must be a non-null constant.",
3241 &CI);
3239 CS);
32423240 }
32433241 }
32443242
3245 Assert(CI.getParent()->getParent()->hasGC(),
3246 "Enclosing function does not use GC.", &CI);
3243 Assert(CS.getParent()->getParent()->hasGC(),
3244 "Enclosing function does not use GC.", CS);
32473245 break;
32483246 case Intrinsic::init_trampoline:
3249 Assert(isa(CI.getArgOperand(1)->stripPointerCasts()),
3247 Assert(isa(CS.getArgOperand(1)->stripPointerCasts()),
32503248 "llvm.init_trampoline parameter #2 must resolve to a function.",
3251 &CI);
3249 CS);
32523250 break;
32533251 case Intrinsic::prefetch:
3254 Assert(isa(CI.getArgOperand(1)) &&
3255 isa(CI.getArgOperand(2)) &&
3256 cast(CI.getArgOperand(1))->getZExtValue() < 2 &&
3257 cast(CI.getArgOperand(2))->getZExtValue() < 4,
3258 "invalid arguments to llvm.prefetch", &CI);
3252 Assert(isa(CS.getArgOperand(1)) &&
3253 isa(CS.getArgOperand(2)) &&
3254 cast(CS.getArgOperand(1))->getZExtValue() < 2 &&
3255 cast(CS.getArgOperand(2))->getZExtValue() < 4,
3256 "invalid arguments to llvm.prefetch", CS);
32593257 break;
32603258 case Intrinsic::stackprotector:
3261 Assert(isa(CI.getArgOperand(1)->stripPointerCasts()),
3262 "llvm.stackprotector parameter #2 must resolve to an alloca.", &CI);
3259 Assert(isa(CS.getArgOperand(1)->stripPointerCasts()),
3260 "llvm.stackprotector parameter #2 must resolve to an alloca.", CS);
32633261 break;
32643262 case Intrinsic::lifetime_start:
32653263 case Intrinsic::lifetime_end:
32663264 case Intrinsic::invariant_start:
3267 Assert(isa(CI.getArgOperand(0)),
3265 Assert(isa(CS.getArgOperand(0)),
32683266 "size argument of memory use markers must be a constant integer",
3269 &CI);
3267 CS);
32703268 break;
32713269 case Intrinsic::invariant_end:
3272 Assert(isa(CI.getArgOperand(1)),
3273 "llvm.invariant.end parameter #2 must be a constant integer", &CI);
3270 Assert(isa(CS.getArgOperand(1)),
3271 "llvm.invariant.end parameter #2 must be a constant integer", CS);
32743272 break;
32753273
32763274 case Intrinsic::frameescape: {
3277 BasicBlock *BB = CI.getParent();
3275 BasicBlock *BB = CS.getParent();
32783276 Assert(BB == &BB->getParent()->front(),
3279 "llvm.frameescape used outside of entry block", &CI);
3277 "llvm.frameescape used outside of entry block", CS);
32803278 Assert(!SawFrameEscape,
3281 "multiple calls to llvm.frameescape in one function", &CI);
3282 for (Value *Arg : CI.args()) {
3279 "multiple calls to llvm.frameescape in one function", CS);
3280 for (Value *Arg : CS.args()) {
32833281 if (isa(Arg))
32843282 continue; // Null values are allowed as placeholders.
32853283 auto *AI = dyn_cast(Arg->stripPointerCasts());
32863284 Assert(AI && AI->isStaticAlloca(),
3287 "llvm.frameescape only accepts static allocas", &CI);
3288 }
3289 FrameEscapeInfo[BB->getParent()].first = CI.getNumArgOperands();
3285 "llvm.frameescape only accepts static allocas", CS);
3286 }
3287 FrameEscapeInfo[BB->getParent()].first = CS.getNumArgOperands();
32903288 SawFrameEscape = true;
32913289 break;
32923290 }
32933291 case Intrinsic::framerecover: {
3294 Value *FnArg = CI.getArgOperand(0)->stripPointerCasts();
3292 Value *FnArg = CS.getArgOperand(0)->stripPointerCasts();
32953293 Function *Fn = dyn_cast(FnArg);
32963294 Assert(Fn && !Fn->isDeclaration(),
32973295 "llvm.framerecover first "
32983296 "argument must be function defined in this module",
3299 &CI);
3300 auto *IdxArg = dyn_cast(CI.getArgOperand(2));
3297 CS);
3298 auto *IdxArg = dyn_cast(CS.getArgOperand(2));
33013299 Assert(IdxArg, "idx argument of llvm.framerecover must be a constant int",
3302 &CI);
3300 CS);
33033301 auto &Entry = FrameEscapeInfo[Fn];
33043302 Entry.second = unsigned(
33053303 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
33073305 }
33083306
33093307 case Intrinsic::experimental_gc_statepoint:
3310 Assert(!CI.isInlineAsm(),
3311 "gc.statepoint support for inline assembly unimplemented", &CI);
3312 Assert(CI.getParent()->getParent()->hasGC(),
3313 "Enclosing function does not use GC.", &CI);
3314
3315 VerifyStatepoint(ImmutableCallSite(CI));
3308 Assert(!CS.isInlineAsm(),
3309 "gc.statepoint support for inline assembly unimplemented", CS);
3310 Assert(CS.getParent()->getParent()->hasGC(),
3311 "Enclosing function does not use GC.", CS);
3312
3313 VerifyStatepoint(CS);
33163314 break;
33173315 case Intrinsic::experimental_gc_result_int:
33183316 case Intrinsic::experimental_gc_result_float:
33193317 case Intrinsic::experimental_gc_result_ptr:
33203318 case Intrinsic::experimental_gc_result: {
3321 Assert(CI.getParent()->getParent()->hasGC(),
3322 "Enclosing function does not use GC.", &CI);
3319 Assert(CS.getParent()->getParent()->hasGC(),
3320 "Enclosing function does not use GC.", CS);
33233321 // Are we tied to a statepoint properly?
3324 CallSite StatepointCS(CI.getArgOperand(0));
3322 CallSite StatepointCS(CS.getArgOperand(0));
33253323 const Function *StatepointFn =
33263324 StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() : nullptr;
33273325 Assert(StatepointFn && StatepointFn->isDeclaration() &&
33283326 StatepointFn->getIntrinsicID() ==
33293327 Intrinsic::experimental_gc_statepoint,
3330 "gc.result operand #1 must be from a statepoint", &CI,
3331 CI.getArgOperand(0));
3328 "gc.result operand #1 must be from a statepoint", CS,
3329 CS.getArgOperand(0));
33323330
33333331 // Assert that result type matches wrapped callee.
33343332 const Value *Target = StatepointCS.getArgument(2);
33353333 const PointerType *PT = cast(Target->getType());
33363334 const FunctionType *TargetFuncType =
33373335 cast(PT->getElementType());
3338 Assert(CI.getType() == TargetFuncType->getReturnType(),
3339 "gc.result result type does not match wrapped callee", &CI);
3336 Assert(CS.getType() == TargetFuncType->getReturnType(),
3337 "gc.result result type does not match wrapped callee", CS);
33403338 break;
33413339 }
33423340 case Intrinsic::experimental_gc_relocate: {
3343 Assert(CI.getNumArgOperands() == 3, "wrong number of arguments", &CI);
3341 Assert(CS.getNumArgOperands() == 3, "wrong number of arguments", CS);
33443342
33453343 // Check that this relocate is correctly tied to the statepoint
33463344
33473345 // This is case for relocate on the unwinding path of an invoke statepoint
33483346 if (ExtractValueInst *ExtractValue =
3349 dyn_cast(CI.getArgOperand(0))) {
3347 dyn_cast(CS.getArgOperand(0))) {
33503348 Assert(isa(ExtractValue->getAggregateOperand()),
33513349 "gc relocate on unwind path incorrectly linked to the statepoint",
3352 &CI);
3350 CS);
33533351
33543352 const BasicBlock *InvokeBB =
33553353 ExtractValue->getParent()->getUniquePredecessor();
33673365 // In all other cases relocate should be tied to the statepoint directly.
33683366 // This covers relocates on a normal return path of invoke statepoint and
33693367 // relocates of a call statepoint
3370 auto Token = CI.getArgOperand(0);
3368 auto Token = CS.getArgOperand(0);
33713369 Assert(isa(Token) && isStatepoint(cast(Token)),
3372 "gc relocate is incorrectly tied to the statepoint", &CI, Token);
3370 "gc relocate is incorrectly tied to the statepoint", CS, Token);
33733371 }
33743372
33753373 // Verify rest of the relocate arguments
33763374
3377 GCRelocateOperands Ops(CI);
3375 GCRelocateOperands Ops(CS);
33783376 ImmutableCallSite StatepointCS(Ops.getStatepoint());
33793377
33803378 // Both the base and derived must be piped through the safepoint
3381 Value* Base = CI.getArgOperand(1);
3379 Value* Base = CS.getArgOperand(1);
33823380 Assert(isa(Base),
3383 "gc.relocate operand #2 must be integer offset", &CI);
3384
3385 Value* Derived = CI.getArgOperand(2);
3381 "gc.relocate operand #2 must be integer offset", CS);
3382
3383 Value* Derived = CS.getArgOperand(2);
33863384 Assert(isa(Derived),
3387 "gc.relocate operand #3 must be integer offset", &CI);
3385 "gc.relocate operand #3 must be integer offset", CS);
33883386
33893387 const int BaseIndex = cast(Base)->getZExtValue();
33903388 const int DerivedIndex = cast(Derived)->getZExtValue();
33913389 // Check the bounds
33923390 Assert(0 <= BaseIndex && BaseIndex < (int)StatepointCS.arg_size(),
3393 "gc.relocate: statepoint base index out of bounds", &CI);
3391 "gc.relocate: statepoint base index out of bounds", CS);
33943392 Assert(0 <= DerivedIndex && DerivedIndex < (int)StatepointCS.arg_size(),
3395 "gc.relocate: statepoint derived index out of bounds", &CI);
3393 "gc.relocate: statepoint derived index out of bounds", CS);
33963394
33973395 // Check that BaseIndex and DerivedIndex fall within the 'gc parameters'
33983396 // section of the statepoint's argument
34213419 Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,
34223420 "gc.relocate: statepoint base index doesn't fall within the "
34233421 "'gc parameters' section of the statepoint call",
3424 &CI);
3422 CS);
34253423 Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,
34263424 "gc.relocate: statepoint derived index doesn't fall within the "
34273425 "'gc parameters' section of the statepoint call",
3428 &CI);
3426 CS);
34293427
34303428 // Relocated value must be a pointer type, but gc_relocate does not need to return the
34313429 // same pointer type as the relocated pointer. It can be casted to the correct type later
34323430 // if it's desired. However, they must have the same address space.
3433 GCRelocateOperands Operands(CI);
3431 GCRelocateOperands Operands(CS);
34343432 Assert(Operands.getDerivedPtr()->getType()->isPointerTy(),
3435 "gc.relocate: relocated value must be a gc pointer", &CI);
3433 "gc.relocate: relocated value must be a gc pointer", CS);
34363434
34373435 // gc_relocate return type must be a pointer type, and is verified earlier in
34383436 // VerifyIntrinsicType().
3439 Assert(cast(CI.getType())->getAddressSpace() ==
3437 Assert(cast(CS.getType())->getAddressSpace() ==
34403438 cast(Operands.getDerivedPtr()->getType())->getAddressSpace(),
3441 "gc.relocate: relocating a pointer shouldn't change its address space", &CI);
3439 "gc.relocate: relocating a pointer shouldn't change its address space", CS);
34423440 break;
34433441 }
34443442 };