about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJulian Büning <julian.buening@rwth-aachen.de>2019-09-15 17:14:18 +0200
committerMartinNowack <martin.nowack@gmail.com>2019-10-31 15:35:05 +0000
commitea9cffdf2902e14f52b442517eebd3a05b742e8a (patch)
treeedc681069dcd4dad44c84d07eeec373259af420f
parenta4f386919bee975c05eced0e56e99dc0d59599ef (diff)
downloadklee-ea9cffdf2902e14f52b442517eebd3a05b742e8a.tar.gz
LLVM 9.0: fourth parameter for @llvm.objectsize()
-rw-r--r--lib/Module/IntrinsicCleaner.cpp18
-rw-r--r--test/Intrinsics/objectsize.leq80.ll35
-rw-r--r--test/Intrinsics/objectsize.ll10
3 files changed, 55 insertions, 8 deletions
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index 1c30d781..144be0ce 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -296,7 +296,9 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
       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.
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0)
+        assert(ii->getNumArgOperands() == 4 && "wrong number of arguments");
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
         assert(ii->getNumArgOperands() == 3 && "wrong number of arguments");
 #else
         assert(ii->getNumArgOperands() == 2 && "wrong number of arguments");
@@ -311,12 +313,22 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
 
 #if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
         auto nullArg = ii->getArgOperand(2);
-        assert(nullArg && "Failed to get second argument");
+        assert(nullArg && "Failed to get third argument");
         auto nullArgAsInt = dyn_cast<ConstantInt>(nullArg);
         assert(nullArgAsInt && "Third arg is not a ConstantInt");
         assert(nullArgAsInt->getBitWidth() == 1 &&
                "Third argument is not an i1");
-	/* TODO should we do something with the 3rd argument? */
+        // TODO: should we do something with the 3rd argument?
+#endif
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0)
+        auto dynamicArg = ii->getArgOperand(3);
+        assert(dynamicArg && "Failed to get fourth argument");
+        auto dynamicArgAsInt = dyn_cast<ConstantInt>(dynamicArg);
+        assert(dynamicArgAsInt && "Fourth arg is not a ConstantInt");
+        assert(dynamicArgAsInt->getBitWidth() == 1 &&
+               "Fourth argument is not an i1");
+        // TODO: should we do something with the 4th argument?
 #endif
 
         Value *replacement = NULL;
diff --git a/test/Intrinsics/objectsize.leq80.ll b/test/Intrinsics/objectsize.leq80.ll
new file mode 100644
index 00000000..f1bcdf62
--- /dev/null
+++ b/test/Intrinsics/objectsize.leq80.ll
@@ -0,0 +1,35 @@
+; REQUIRES: lt-llvm-9.0
+; LLVM 5 added parameter "nullunknown" to @llvm.objectsize
+; REQUIRES: geq-llvm-5.0
+; RUN: %llvmas %s -o=%t.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee -exit-on-error --output-dir=%t.klee-out --optimize=false %t.bc
+; ModuleID = 'objectsize.c'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @main() nounwind uwtable {
+entry:
+  %a = alloca i8*, align 8
+  %0 = load i8*, i8** %a, align 8
+  %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %0, i1 true, i1 false)
+  %cmp = icmp ne i64 %1, 0
+  br i1 %cmp, label %abort.block, label %continue.block
+
+continue.block:
+  %2 = load i8*, i8** %a, align 8
+  %3 = call i64 @llvm.objectsize.i64.p0i8(i8* %2, i1 false, i1 false)
+  %cmp1 = icmp ne i64 %3, -1
+  br i1 %cmp1, label %abort.block, label %exit.block
+
+exit.block:
+  ret i32 0
+
+abort.block:
+  call void @abort()
+  unreachable
+}
+
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1) nounwind readnone
+
+declare void @abort() noreturn nounwind
diff --git a/test/Intrinsics/objectsize.ll b/test/Intrinsics/objectsize.ll
index 4b2110cb..af77baa4 100644
--- a/test/Intrinsics/objectsize.ll
+++ b/test/Intrinsics/objectsize.ll
@@ -1,5 +1,5 @@
-; LLVM 5 added nullunknown parameter to @llvm.objectsize
-; REQUIRES: geq-llvm-5.0
+; LLVM 9 added parameter "dynamic" to @llvm.objectsize
+; REQUIRES: geq-llvm-9.0
 ; RUN: %llvmas %s -o=%t.bc
 ; RUN: rm -rf %t.klee-out
 ; RUN: %klee -exit-on-error --output-dir=%t.klee-out --optimize=false %t.bc
@@ -11,13 +11,13 @@ define i32 @main() nounwind uwtable {
 entry:
   %a = alloca i8*, align 8
   %0 = load i8*, i8** %a, align 8
-  %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %0, i1 true, i1 false)
+  %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %0, i1 true, i1 false, i1 false)
   %cmp = icmp ne i64 %1, 0
   br i1 %cmp, label %abort.block, label %continue.block
 
 continue.block:
   %2 = load i8*, i8** %a, align 8
-  %3 = call i64 @llvm.objectsize.i64.p0i8(i8* %2, i1 false, i1 false)
+  %3 = call i64 @llvm.objectsize.i64.p0i8(i8* %2, i1 false, i1 false, i1 false)
   %cmp1 = icmp ne i64 %3, -1
   br i1 %cmp1, label %abort.block, label %exit.block
 
@@ -29,6 +29,6 @@ abort.block:
   unreachable
 }
 
-declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1) nounwind readnone
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1) nounwind readnone
 
 declare void @abort() noreturn nounwind