2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | 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
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
void test5() {
|
2010-01-14 03:40:37 +08:00
|
|
|
// CHECK: = load i8** @gp
|
|
|
|
// CHECK-NEXT:= call i64 @llvm.objectsize.i64(i8* %{{.*}}, i1 false)
|
2009-10-27 05:38:39 +08:00
|
|
|
strcpy(gp, "Hi there");
|
2009-10-27 02:35:08 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
void test7() {
|
|
|
|
int i;
|
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* 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:22:14 +08:00
|
|
|
strcpy((++i, gbuf), "Hi there");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void test11() {
|
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 = gbuf, "Hi there");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
}
|