summaryrefslogtreecommitdiff
path: root/test/CodeGen
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-11-04 15:04:32 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-11-04 15:04:32 +0000
commit51fb8b013e7734b795139f49d3b1f77c539be20a (patch)
tree59e0e47a9831dcf0e21e547927c8ebb7e113bfd1 /test/CodeGen
parent73490b890977362d28dd6326843a1ecae413921d (diff)
Notes
Diffstat (limited to 'test/CodeGen')
-rw-r--r--test/CodeGen/2008-07-21-mixed-var-fn-decl.c5
-rw-r--r--test/CodeGen/2008-07-29-override-alias-decl.c15
-rw-r--r--test/CodeGen/asm-inout.c2
-rw-r--r--test/CodeGen/blocks-2.c2
-rw-r--r--test/CodeGen/builtin-unwind-init.c5
-rw-r--r--test/CodeGen/cast-to-union.c2
-rw-r--r--test/CodeGen/function-attributes.c56
-rw-r--r--test/CodeGen/indirect-goto.c23
-rw-r--r--test/CodeGen/mangle.c23
-rw-r--r--test/CodeGen/object-size.c126
-rw-r--r--test/CodeGen/union-init2.c2
-rw-r--r--test/CodeGen/volatile.c10
12 files changed, 226 insertions, 45 deletions
diff --git a/test/CodeGen/2008-07-21-mixed-var-fn-decl.c b/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
index c55c86b2fc6c7..59a3f38849518 100644
--- a/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
+++ b/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
@@ -1,5 +1,8 @@
-// RUN: clang-cc -emit-llvm -o - %s | grep -e "@g[0-9] " | count 2
+// RUN: clang-cc -emit-llvm -o - %s | FileCheck %s
int g0, f0();
int f1(), g1;
+// CHECK: @g0 = common global i32 0, align 4
+// CHECK: @g1 = common global i32 0, align 4
+
diff --git a/test/CodeGen/2008-07-29-override-alias-decl.c b/test/CodeGen/2008-07-29-override-alias-decl.c
index 4a36e0f13d5c6..872950029618b 100644
--- a/test/CodeGen/2008-07-29-override-alias-decl.c
+++ b/test/CodeGen/2008-07-29-override-alias-decl.c
@@ -1,7 +1,13 @@
-// RUN: clang-cc -emit-llvm -o - %s | grep -e "^@f" | count 1
+// RUN: clang-cc -emit-llvm -o - %s | FileCheck %s
int x() { return 1; }
+// CHECK: %retval = alloca i32
+// CHECK: store i32 1, i32* %retval
+// CHECK: %0 = load i32* %retval
+// CHECK: ret i32 %0
+
+
int f() __attribute__((weak, alias("x")));
/* Test that we link to the alias correctly instead of making a new
@@ -10,3 +16,10 @@ int f();
int h() {
return f();
}
+
+// CHECK: %retval = alloca i32
+// CHECK: %call = call i32 (...)* @f()
+// CHECK: store i32 %call, i32* %retval
+// CHECK: %0 = load i32* %retval
+// CHECK: ret i32 %0
+
diff --git a/test/CodeGen/asm-inout.c b/test/CodeGen/asm-inout.c
index 0d8dbdfb9d381..bd287ad0ee69d 100644
--- a/test/CodeGen/asm-inout.c
+++ b/test/CodeGen/asm-inout.c
@@ -1,6 +1,6 @@
// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm %s -o %t &&
// RUN: grep "load i8\*\*\* %p.addr" %t | count 1
-// XFAIL
+// XFAIL: *
// PR3800
void f(void **p)
diff --git a/test/CodeGen/blocks-2.c b/test/CodeGen/blocks-2.c
index bc6c2b916abd0..acbaafd95605c 100644
--- a/test/CodeGen/blocks-2.c
+++ b/test/CodeGen/blocks-2.c
@@ -1,7 +1,7 @@
// RUN: clang-cc -g %s -emit-llvm -o %t -fblocks &&
// RUN: grep "func.start" %t | count 4
// 1 declaration, 1 bar, 1 test_block_dbg and 1 for the block.
-// XFAIL
+// XFAIL: *
static __inline__ __attribute__((always_inline)) int bar(int va, int vb) { return (va == vb); }
diff --git a/test/CodeGen/builtin-unwind-init.c b/test/CodeGen/builtin-unwind-init.c
index 49a016a304f0c..56872f7434eee 100644
--- a/test/CodeGen/builtin-unwind-init.c
+++ b/test/CodeGen/builtin-unwind-init.c
@@ -1,4 +1,5 @@
-// RUN: clang-cc -emit-llvm < %s -o - | grep -F "llvm.eh.unwind.init"
+// RUN: clang-cc -emit-llvm < %s -o - | FileCheck %s
-int a() { __builtin_unwind_init(); }
+void a() { __builtin_unwind_init(); }
+// CHECK: call void @llvm.eh.unwind.init()
diff --git a/test/CodeGen/cast-to-union.c b/test/CodeGen/cast-to-union.c
index 674299294928b..1f7e0457706d6 100644
--- a/test/CodeGen/cast-to-union.c
+++ b/test/CodeGen/cast-to-union.c
@@ -1,5 +1,5 @@
// RUN: clang-cc -emit-llvm %s -o - | FileCheck %s
-// CHECK: w = global %0 { i32 2, [4 x i8] zeroinitializer }
+// CHECK: w = global %0 { i32 2, [4 x i8] undef }
// CHECK: y = global %union.u { double 7.300000e+0{{[0]*}}1 }
// CHECK: store i32 351, i32
diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c
index d2d3b031a83b2..b09b28b8d93d3 100644
--- a/test/CodeGen/function-attributes.c
+++ b/test/CodeGen/function-attributes.c
@@ -1,12 +1,12 @@
-// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm -o %t %s &&
-// RUN: grep 'define signext i8 @f0(i32 %x) nounwind' %t &&
-// RUN: grep 'define zeroext i8 @f1(i32 %x) nounwind' %t &&
-// RUN: grep 'define void @f2(i8 signext %x) nounwind' %t &&
-// RUN: grep 'define void @f3(i8 zeroext %x) nounwind' %t &&
-// RUN: grep 'define signext i16 @f4(i32 %x) nounwind' %t &&
-// RUN: grep 'define zeroext i16 @f5(i32 %x) nounwind' %t &&
-// RUN: grep 'define void @f6(i16 signext %x) nounwind' %t &&
-// RUN: grep 'define void @f7(i16 zeroext %x) nounwind' %t &&
+// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s
+// CHECK: define signext i8 @f0(i32 %x) nounwind
+// CHECK: define zeroext i8 @f1(i32 %x) nounwind
+// CHECK: define void @f2(i8 signext %x) nounwind
+// CHECK: define void @f3(i8 zeroext %x) nounwind
+// CHECK: define signext i16 @f4(i32 %x) nounwind
+// CHECK: define zeroext i16 @f5(i32 %x) nounwind
+// CHECK: define void @f6(i16 signext %x) nounwind
+// CHECK: define void @f7(i16 zeroext %x) nounwind
signed char f0(int x) { return x; }
@@ -24,15 +24,22 @@ void f6(signed short x) { }
void f7(unsigned short x) { }
-// RUN: grep 'define void @f8() nounwind alwaysinline' %t &&
+// CHECK: define void @f8()
+// CHECK: nounwind
+// CHECK: alwaysinline
+// CHECK: {
void __attribute__((always_inline)) f8(void) { }
-// RUN: grep 'call void @f9_t() noreturn' %t &&
+// CHECK: call void @f9_t()
+// CHECK: noreturn
+// CHECK: {
void __attribute__((noreturn)) f9_t(void);
void f9(void) { f9_t(); }
// FIXME: We should be setting nounwind on calls.
-// RUN: grep 'call i32 @f10_t() readnone' %t &&
+// CHECK: call i32 @f10_t()
+// CHECK: readnone
+// CHECK: {
int __attribute__((const)) f10_t(void);
int f10(void) { return f10_t(); }
int f11(void) {
@@ -43,13 +50,15 @@ int f12(int arg) {
return arg ? 0 : f10_t();
}
-// RUN: grep 'define void @f13() nounwind readnone' %t &&
+// CHECK: define void @f13() nounwind readnone
void f13(void) __attribute__((pure)) __attribute__((const));
void f13(void){}
// Ensure that these get inlined: rdar://6853279
-// RUN: not grep '@ai_' %t &&
+// CHECK: define void @f14
+// CHECK-NOT: @ai_
+// CHECK: call void @f14_end
static __inline__ __attribute__((always_inline))
int ai_1() { return 4; }
@@ -58,12 +67,17 @@ struct {
int a, b, c, d, e;
} ai_2() { while (1) {} }
-
-int foo() {
- ai_2();
- return ai_1();
+void f14(int a) {
+ extern void f14_end(void);
+ if (a)
+ ai_2();
+ ai_1();
+ f14_end();
}
-
-
-// RUN: true
+// <rdar://problem/7102668> [irgen] clang isn't setting the optsize bit on functions
+// CHECK: define void @f15
+// CHECK: optsize
+// CHECK: {
+void f15(void) {
+}
diff --git a/test/CodeGen/indirect-goto.c b/test/CodeGen/indirect-goto.c
index b9a6019538771..6804f5739bbff 100644
--- a/test/CodeGen/indirect-goto.c
+++ b/test/CodeGen/indirect-goto.c
@@ -1,9 +1,7 @@
-// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm-bc -o - %s | opt -std-compile-opts | llvm-dis > %t &&
-// RUN: grep "ret i32" %t | count 1 &&
-// RUN: grep "ret i32 210" %t | count 1
+// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm-bc -o - %s | opt -std-compile-opts -S | grep "ret i32 2520"
static int foo(unsigned i) {
- const void *addrs[] = { &&L1, &&L2, &&L3, &&L4, &&L5 };
+ void *addrs[] = { &&L1, &&L2, &&L3, &&L4, &&L5 };
int res = 1;
goto *addrs[i];
@@ -15,6 +13,19 @@ static int foo(unsigned i) {
return res;
}
-int bar() {
- return foo(3);
+static int foo2(unsigned i) {
+ static const void *addrs[] = { &&L1, &&L2, &&L3, &&L4, &&L5 };
+ int res = 1;
+
+ goto *addrs[i];
+L5: res *= 11;
+L4: res *= 7;
+L3: res *= 5;
+L2: res *= 3;
+L1: res *= 2;
+ return res;
+}
+
+int main() {
+ return foo(3)+foo2(4);
}
diff --git a/test/CodeGen/mangle.c b/test/CodeGen/mangle.c
index 17d74ba71f0c5..6f42f6f6496cc 100644
--- a/test/CodeGen/mangle.c
+++ b/test/CodeGen/mangle.c
@@ -1,22 +1,20 @@
-// RUN: clang-cc -triple i386-pc-linux-gnu -emit-llvm -o %t %s &&
-// RUN: grep '@_Z2f0i' %t &&
-// RUN: grep '@_Z2f0l' %t &&
+// RUN: clang-cc -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
-// Make sure we mangle overloadable, even in C system headers.
+// CHECK: @"\01foo"
+// Make sure we mangle overloadable, even in C system headers.
# 1 "somesystemheader.h" 1 3 4
+// CHECK: @_Z2f0i
void __attribute__((__overloadable__)) f0(int a) {}
+// CHECK: @_Z2f0l
void __attribute__((__overloadable__)) f0(long b) {}
-
+// CHECK: @"\01bar"
// These should get merged.
void foo() __asm__("bar");
void foo2() __asm__("bar");
-// RUN: grep '@"\\01foo"' %t &&
-// RUN: grep '@"\\01bar"' %t
-
int nux __asm__("foo");
extern float nux2 __asm__("foo");
@@ -52,3 +50,12 @@ void foo6() {
int foo7 __asm__("foo7") __attribute__((used));
float foo8 __asm__("foo7") = 42;
+
+// PR4412
+int func(void);
+extern int func (void) __asm__ ("FUNC");
+
+// CHECK: @"\01FUNC"
+int func(void) {
+ return 42;
+}
diff --git a/test/CodeGen/object-size.c b/test/CodeGen/object-size.c
new file mode 100644
index 0000000000000..61d85419fc696
--- /dev/null
+++ b/test/CodeGen/object-size.c
@@ -0,0 +1,126 @@
+// RUN: clang-cc -triple x86_64-apple-darwin -S %s -o - | FileCheck %s
+
+#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));
+}
+
+char gbuf[63];
+char *gp;
+int gi, gj;
+
+void test1() {
+ // CHECK: movabsq $59, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(&gbuf[4], "Hi there");
+}
+
+void test2() {
+ // CHECK: movabsq $63, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(gbuf, "Hi there");
+}
+
+void test3() {
+ // CHECK: movabsq $0, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(&gbuf[100], "Hi there");
+}
+
+void test4() {
+ // CHECK: movabsq $0, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy((char*)(void*)&gbuf[-1], "Hi there");
+}
+
+void test5() {
+ // CHECK: movb $0, %al
+ // CHECK-NEXT: testb %al, %al
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(gp, "Hi there");
+}
+
+void test6() {
+ char buf[57];
+
+ // CHECK: movabsq $53, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(&buf[4], "Hi there");
+}
+
+void test7() {
+ int i;
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy((++i, gbuf), "Hi there");
+}
+
+void test8() {
+ char *buf[50];
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(buf[++gi], "Hi there");
+}
+
+void test9() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy((char *)((++gi) + gj), "Hi there");
+}
+
+char **p;
+void test10() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(*(++p), "Hi there");
+}
+
+void test11() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(gp = gbuf, "Hi there");
+}
+
+void test12() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(++gp, "Hi there");
+}
+
+void test13() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(gp++, "Hi there");
+}
+
+void test14() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(--gp, "Hi there");
+}
+
+void test15() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(gp--, "Hi there");
+}
+
+void test16() {
+ // CHECK-NOT: call ___strcpy_chk
+ // CHECK: call ___inline_strcpy_chk
+ strcpy(gp += 1, "Hi there");
+}
diff --git a/test/CodeGen/union-init2.c b/test/CodeGen/union-init2.c
index 184d75f47156a..e782425cf2b11 100644
--- a/test/CodeGen/union-init2.c
+++ b/test/CodeGen/union-init2.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm %s -o - -triple i686-pc-linux-gnu | grep "bitcast (%0\* @r to %union.x\*), \[4 x i8\] zeroinitializer"
+// RUN: clang-cc -emit-llvm %s -o - -triple i686-pc-linux-gnu | grep "bitcast (%0\* @r to %union.x\*), \[4 x i8\] undef"
// Make sure we generate something sane instead of a ptrtoint
union x {long long b;union x* a;} r = {.a = &r};
diff --git a/test/CodeGen/volatile.c b/test/CodeGen/volatile.c
index 87cb5ff4eb4f5..e17669008a393 100644
--- a/test/CodeGen/volatile.c
+++ b/test/CodeGen/volatile.c
@@ -1,8 +1,8 @@
// RUN: clang-cc -emit-llvm < %s -o %t &&
-// RUN: grep volatile %t | count 25 &&
+// RUN: grep volatile %t | count 29 &&
// RUN: grep memcpy %t | count 7
-// The number 25 comes from the current codegen for volatile loads;
+// The number 29 comes from the current codegen for volatile loads;
// if this number changes, it's not necessarily something wrong, but
// something has changed to affect volatile load/store codegen
@@ -38,6 +38,9 @@ volatile extv4 vVE;
volatile struct {int x;} aggFct(void);
+typedef volatile int volatile_int;
+volatile_int vtS;
+
int main() {
int i;
@@ -62,6 +65,7 @@ int main() {
i=VE.yx[1];
i=vVE.zy[1];
i = aggFct().x;
+ i=vtS;
// store
@@ -81,12 +85,14 @@ int main() {
vBF.x=i;
V[3]=i;
vV[3]=i;
+ vtS=i;
// other ops:
++S;
++vS;
i+=S;
i+=vS;
+ ++vtS;
(void)vF2;
vF2 = vF2;
vF2 = vF2 = vF2;