• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test that the StrCpyOptimizer works correctly
2; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
3
4; This transformation requires the pointer size, as it assumes that size_t is
5; the size of a pointer.
6target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
7
8@hello = constant [6 x i8] c"hello\00"
9
10declare i8* @strcpy(i8*, i8*)
11
12declare i8* @__strcpy_chk(i8*, i8*, i32) nounwind
13
14declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
15
16; rdar://6839935
17
18define i32 @t1() {
19; CHECK: @t1
20  %target = alloca [1024 x i8]
21  %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
22  %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
23  %rslt1 = call i8* @strcpy( i8* %arg1, i8* %arg2 )
24; CHECK: @llvm.memcpy.p0i8.p0i8.i32
25  ret i32 0
26}
27
28define i32 @t2() {
29; CHECK: @t2
30  %target = alloca [1024 x i8]
31  %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
32  %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
33  %tmp1 = call i32 @llvm.objectsize.i32(i8* %arg1, i1 false)
34  %rslt1 = call i8* @__strcpy_chk(i8* %arg1, i8* %arg2, i32 %tmp1)
35; CHECK: @__memcpy_chk
36  ret i32 0
37}
38