aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-25 17:29:22 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-25 17:29:22 +0000
commite3094283e38d9e6f6a4a7a14a3a5d0f2af67d5d5 (patch)
tree86fed444bf0263f4cfc2a78f815c9b6c59e942f7 /test
parenta536835230afcd334068bc6f5781a244938feaf9 (diff)
MemoryBuiltins: add support to determine the size of strdup'ed non-constant strings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160742 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Instrumentation/BoundsChecking/strings.ll31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/Instrumentation/BoundsChecking/strings.ll b/test/Instrumentation/BoundsChecking/strings.ll
new file mode 100644
index 0000000000..1942d1407b
--- /dev/null
+++ b/test/Instrumentation/BoundsChecking/strings.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+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"
+
+declare noalias i8* @strdup(i8* nocapture) nounwind
+declare noalias i8* @strndup(i8* nocapture, i64) nounwind
+
+; CHECK: @f1
+define i8 @f1(i8* nocapture %str, i8** nocapture %esc) nounwind uwtable ssp {
+; CHECK: call i64 @strlen(i8* %str)
+; CHECK-NEXT: %1 = add nuw i64 {{.*}}, 1
+ %call = tail call i8* @strdup(i8* %str) nounwind
+ store i8* %call, i8** %esc, align 8
+ %arrayidx = getelementptr inbounds i8* %call, i64 3
+; CHECK: sub i64 %1, 3
+ %1 = load i8* %arrayidx, align 1
+ ret i8 %1
+; CHECK: call void @llvm.trap
+}
+
+; CHECK: @f2
+define i8 @f2(i8* nocapture %str, i8** nocapture %esc, i64 %limit) nounwind uwtable ssp {
+; CHECK: call i64 @strnlen(i8* %str, i64 %limit)
+; CHECK-NEXT: %1 = add nuw i64 {{.*}}, 1
+ %call = tail call i8* @strndup(i8* %str, i64 %limit) nounwind
+ store i8* %call, i8** %esc, align 8
+ %arrayidx = getelementptr inbounds i8* %call, i64 3
+; CHECK: sub i64 %1, 3
+ %1 = load i8* %arrayidx, align 1
+ ret i8 %1
+; CHECK: call void @llvm.trap
+}