2012-07-14 04:48:52 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s
|
2009-10-27 20:19:13 +08:00
|
|
|
|
|
|
|
#define strcpy(dest, src) \
|
|
|
|
((__builtin_object_size(dest, 0) != -1ULL) \
|
|
|
|
? __builtin___strcpy_chk (dest, src, __builtin_object_size(dest, 1)) \
|
|
|
|
: __inline_strcpy_chk(dest, src))
|
|
|
|
|
|
|
|
static char *__inline_strcpy_chk (char *dest, const char *src) {
|
|
|
|
return __builtin___strcpy_chk(dest, src, __builtin_object_size(dest, 1));
|
|
|
|
}
|
2009-10-27 02:35:08 +08:00
|
|
|
|
|
|
|
char gbuf[63];
|
|
|
|
char *gp;
|
2009-10-30 07:22:14 +08:00
|
|
|
int gi, gj;
|
2009-10-27 02:35:08 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test1
|
2009-10-27 02:35:08 +08:00
|
|
|
void test1() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i64 4), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 59)
|
2009-10-27 02:35:08 +08:00
|
|
|
strcpy(&gbuf[4], "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test2
|
2009-10-27 02:35:08 +08:00
|
|
|
void test2() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 63)
|
2009-10-27 02:35:08 +08:00
|
|
|
strcpy(gbuf, "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test3
|
2009-10-27 05:38:39 +08:00
|
|
|
void test3() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i64 1, i64 37), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 0)
|
2009-10-27 05:38:39 +08:00
|
|
|
strcpy(&gbuf[100], "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test4
|
2009-10-27 02:35:08 +08:00
|
|
|
void test4() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i64 -1), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 0)
|
2009-10-27 05:38:39 +08:00
|
|
|
strcpy((char*)(void*)&gbuf[-1], "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test5
|
2009-10-27 05:38:39 +08:00
|
|
|
void test5() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = load i8** @gp
|
2013-10-08 03:00:18 +08:00
|
|
|
// CHECK-NEXT:= call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
|
2009-10-27 05:38:39 +08:00
|
|
|
strcpy(gp, "Hi there");
|
2009-10-27 02:35:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test6
|
2009-10-27 05:38:39 +08:00
|
|
|
void test6() {
|
2009-10-27 07:05:19 +08:00
|
|
|
char buf[57];
|
|
|
|
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 53)
|
2009-10-27 07:05:19 +08:00
|
|
|
strcpy(&buf[4], "Hi there");
|
|
|
|
}
|
2009-10-30 07:22:14 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test7
|
2009-10-30 07:22:14 +08:00
|
|
|
void test7() {
|
|
|
|
int i;
|
2012-05-23 12:13:20 +08:00
|
|
|
// Ensure we only evaluate the side-effect once.
|
|
|
|
// CHECK: = add
|
|
|
|
// CHECK-NOT: = add
|
|
|
|
// CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 63)
|
2009-10-30 07:22:14 +08:00
|
|
|
strcpy((++i, gbuf), "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test8
|
2009-10-30 07:22:14 +08:00
|
|
|
void test8() {
|
|
|
|
char *buf[50];
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:22:14 +08:00
|
|
|
strcpy(buf[++gi], "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test9
|
2009-10-30 07:22:14 +08:00
|
|
|
void test9() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:22:14 +08:00
|
|
|
strcpy((char *)((++gi) + gj), "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test10
|
2009-10-30 07:22:14 +08:00
|
|
|
char **p;
|
|
|
|
void test10() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:22:14 +08:00
|
|
|
strcpy(*(++p), "Hi there");
|
|
|
|
}
|
2009-10-30 07:29:54 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test11
|
2009-10-30 07:29:54 +08:00
|
|
|
void test11() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-06-30 06:00:45 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:29:54 +08:00
|
|
|
strcpy(gp = gbuf, "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test12
|
2009-10-30 07:29:54 +08:00
|
|
|
void test12() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:29:54 +08:00
|
|
|
strcpy(++gp, "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test13
|
2009-10-30 07:29:54 +08:00
|
|
|
void test13() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:29:54 +08:00
|
|
|
strcpy(gp++, "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test14
|
2009-10-30 07:29:54 +08:00
|
|
|
void test14() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:29:54 +08:00
|
|
|
strcpy(--gp, "Hi there");
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test15
|
2009-10-30 07:29:54 +08:00
|
|
|
void test15() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{..*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:29:54 +08:00
|
|
|
strcpy(gp--, "Hi there");
|
|
|
|
}
|
2009-10-30 07:34:20 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test16
|
2009-10-30 07:34:20 +08:00
|
|
|
void test16() {
|
2009-12-08 03:22:29 +08:00
|
|
|
// CHECK-NOT: __strcpy_chk
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0))
|
2009-10-30 07:34:20 +08:00
|
|
|
strcpy(gp += 1, "Hi there");
|
|
|
|
}
|
2010-01-04 02:18:37 +08:00
|
|
|
|
2012-07-14 04:48:52 +08:00
|
|
|
// CHECK: @test17
|
2010-01-04 02:18:37 +08:00
|
|
|
void test17() {
|
|
|
|
// CHECK: store i32 -1
|
|
|
|
gi = __builtin_object_size(gp++, 0);
|
|
|
|
// CHECK: store i32 -1
|
|
|
|
gi = __builtin_object_size(gp++, 1);
|
|
|
|
// CHECK: store i32 0
|
|
|
|
gi = __builtin_object_size(gp++, 2);
|
|
|
|
// CHECK: store i32 0
|
|
|
|
gi = __builtin_object_size(gp++, 3);
|
|
|
|
}
|
2012-07-14 04:48:52 +08:00
|
|
|
|
|
|
|
// CHECK: @test18
|
|
|
|
unsigned test18(int cond) {
|
|
|
|
int a[4], b[4];
|
|
|
|
// CHECK: phi i32*
|
|
|
|
// CHECK: call i64 @llvm.objectsize.i64
|
|
|
|
return __builtin_object_size(cond ? a : b, 0);
|
|
|
|
}
|