diff options
author | Dan Liew <daniel.liew@imperial.ac.uk> | 2015-12-19 11:21:15 +0000 |
---|---|---|
committer | Dan Liew <daniel.liew@imperial.ac.uk> | 2015-12-19 22:04:50 +0000 |
commit | d95825bef428b631099440d01a3955e7f6276b16 (patch) | |
tree | 8806a8b2628a9e111e84eeb0af7f351f519c81cb /lib | |
parent | d348aee430c8308a29d5edadd4c38e7fee1abadc (diff) | |
download | klee-d95825bef428b631099440d01a3955e7f6276b16.tar.gz |
Implement support for lowering the ``llvm.objectsize`` intrinsic
introduced in LLVM 2.7. Previously KLEE would emit the following error message when ``IntrinsicLowering::LowerIntrinsicCall()`` was called on the intrinsic ``` LLVM ERROR: Code generator does not support intrinsic function 'llvm.objectsize.i64.p0i8'! ``` The ``IntrinsicCleaner`` pass now lowers this intrinsic to a constant integer depending on the second argument to the intrinsic. This corresponds to the case where the size of the object pointed to by the first argument is unknown. An alternative design would be to handle this intrinsic in the Executor where is actually possible to know the size of objects during execution. However that would be much more complicated because if the pointer is symbolic we would have to fork for every object that could be pointed to. The implementation is similar to #260 but we handle the second argument to the intrinsic correctly and also have a simple test case. Unfortunately we have to have a different version of the test case for LLVM 2.9 because the expected suffix for the intrinsic is different in LLVM 2.9.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Module/IntrinsicCleaner.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp index da97621a..54ad7db7 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp @@ -232,7 +232,30 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { dirty = true; break; } - + case Intrinsic::objectsize: { + // We don't know the size of an object in general so we replace + // with 0 or -1 depending on the second argument to the intrinsic. + assert(ii->getNumArgOperands() == 2 && "wrong number of arguments"); + Value *minArg = ii->getArgOperand(1); + assert(minArg && "Failed to get second argument"); + ConstantInt *minArgAsInt = dyn_cast<ConstantInt>(minArg); + assert(minArgAsInt && "Second arg is not a ConstantInt"); + assert(minArgAsInt->getBitWidth() == 1 && "Second argument is not an i1"); + Value *replacement = NULL; + LLVM_TYPE_Q IntegerType *intType = dyn_cast<IntegerType>(ii->getType()); + assert(intType && "intrinsic does not have integer return type"); + if (minArgAsInt->isZero()) { + // min=false + replacement = ConstantInt::get(intType, -1, /*isSigned=*/true); + } else { + // min=true + replacement = ConstantInt::get(intType, 0, /*isSigned=*/false); + } + ii->replaceAllUsesWith(replacement); + ii->eraseFromParent(); + dirty = true; + break; + } default: if (LowerIntrinsics) IL->LowerIntrinsicCall(ii); |