about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorDan Liew <delcypher@gmail.com>2015-12-23 11:37:22 +0000
committerDan Liew <delcypher@gmail.com>2015-12-23 11:37:22 +0000
commit2287eb0d44bedd20484874da06615ace3ce4e2a2 (patch)
tree8cfa6e77c3e25512179bf6e33971368363b722e1 /lib
parent3159c9189eed89076d22d8edb7c07a91cb7a1155 (diff)
parentd95825bef428b631099440d01a3955e7f6276b16 (diff)
downloadklee-2287eb0d44bedd20484874da06615ace3ce4e2a2.tar.gz
Merge pull request #323 from delcypher/support_objectsize_intrinsic
Implement support for lowering the ``llvm.objectsize`` intrinsic
Diffstat (limited to 'lib')
-rw-r--r--lib/Module/IntrinsicCleaner.cpp25
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);