Jiri Slaby 2018-05-23 13:11:28 +00:00 committed by Git OBS Bridge
parent eafaf9805f
commit f7338a04e6
5 changed files with 157 additions and 2 deletions

View File

@ -0,0 +1,52 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 23 May 2018 15:01:34 +0200
Subject: llvm50: Intrinsic::objectsize has three arguments
Patch-mainline: no
Modify the IntrinsicCleaner accordingly.
We do not do anything with the third argument as we do not handle the
first argument in any way.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Module/IntrinsicCleaner.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index d4f93bdc591e..e8c63cd334d0 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -230,13 +230,29 @@ 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)
+ assert(ii->getNumArgOperands() == 3 && "wrong number of arguments");
+#else
assert(ii->getNumArgOperands() == 2 && "wrong number of arguments");
+#endif
+
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");
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
+ Value *nullArg = ii->getArgOperand(2);
+ assert(nullArg && "Failed to get second argument");
+ ConstantInt *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? */
+#endif
+
Value *replacement = NULL;
IntegerType *intType = dyn_cast<IntegerType>(ii->getType());
assert(intType && "intrinsic does not have integer return type");
--
2.17.0

View File

@ -0,0 +1,99 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 23 May 2018 14:54:48 +0200
Subject: llvm50: test, change objectsize
Patch-mainline: no
@llvm.objectsize has now three aguments, so fix the tests accordingly.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
test/Intrinsics/objectsize.leq49.ll | 38 +++++++++++++++++++++++++++++
test/Intrinsics/objectsize.ll | 9 ++++---
2 files changed, 43 insertions(+), 4 deletions(-)
create mode 100644 test/Intrinsics/objectsize.leq49.ll
diff --git a/test/Intrinsics/objectsize.leq49.ll b/test/Intrinsics/objectsize.leq49.ll
new file mode 100644
index 000000000000..1d184bdf292d
--- /dev/null
+++ b/test/Intrinsics/objectsize.leq49.ll
@@ -0,0 +1,38 @@
+; Unfortunately LLVM 2.9 has a different suffix for the ``llvm.objectsize`` instrinsic
+; so this LLVM IR fails to verify for that version.
+;
+; LLVM 3.7 requires a type as the first argument to 'load'
+; REQUIRES: geq-llvm-3.7
+; REQUIRES: lt-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 -disable-opt %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)
+ %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)
+ %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) nounwind readnone
+
+declare void @abort() noreturn nounwind
diff --git a/test/Intrinsics/objectsize.ll b/test/Intrinsics/objectsize.ll
index 3a111f99c619..95070e66e45c 100644
--- a/test/Intrinsics/objectsize.ll
+++ b/test/Intrinsics/objectsize.ll
@@ -2,7 +2,8 @@
; so this LLVM IR fails to verify for that version.
;
; LLVM 3.7 requires a type as the first argument to 'load'
-; REQUIRES: geq-llvm-3.7
+; LLVM 5 added nullunknown parameter 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 -disable-opt %t.bc
@@ -14,13 +15,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)
+ %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)
+ %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
@@ -32,6 +33,6 @@ abort.block:
unreachable
}
-declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) nounwind readnone
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1) nounwind readnone
declare void @abort() noreturn nounwind
--
2.17.0

View File

@ -59,8 +59,10 @@ Patch217: 0017-llvm50-SwitchInst-case-functions-now-return-pointers.patch
Patch218: 0018-llvm50-handle-new-file_magic-s-location.patch
Patch219: 0019-llvm50-use-MutableArrayRef-for-APFloat-convertToInte.patch
Patch220: 0020-llvm50-AllocaInst-takes-address-space.patch
Patch221: 0021-llvm60-SetVersionPrinter-now-passes-down-a-stream.patch
Patch222: 0022-llvm60-handle-headers-renaming.patch
Patch221: 0021-llvm50-Intrinsic-objectsize-has-three-arguments.patch
Patch222: 0022-llvm50-test-change-objectsize.patch
Patch223: 0023-llvm60-SetVersionPrinter-now-passes-down-a-stream.patch
Patch224: 0024-llvm60-handle-headers-renaming.patch
Patch300: klee-skip-some-tests.patch
@ -112,6 +114,8 @@ information on what KLEE is and what it can do, see the OSDI 2008 paper.
%patch220 -p1
%patch221 -p1
%patch222 -p1
%patch223 -p1
%patch224 -p1
#%%patch300 -p1