xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/mangle.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // CHECK: @foo
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc // Make sure we mangle overloadable, even in C system headers.
6*f4a2713aSLionel Sambuc # 1 "somesystemheader.h" 1 3 4
7*f4a2713aSLionel Sambuc // CHECK: @_Z2f0i
f0(int a)8*f4a2713aSLionel Sambuc void __attribute__((__overloadable__)) f0(int a) {}
9*f4a2713aSLionel Sambuc // CHECK: @_Z2f0l
f0(long b)10*f4a2713aSLionel Sambuc void __attribute__((__overloadable__)) f0(long b) {}
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc // CHECK: @bar
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc // These should get merged.
15*f4a2713aSLionel Sambuc void foo() __asm__("bar");
16*f4a2713aSLionel Sambuc void foo2() __asm__("bar");
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc int nux __asm__("foo");
19*f4a2713aSLionel Sambuc extern float nux2 __asm__("foo");
20*f4a2713aSLionel Sambuc 
test()21*f4a2713aSLionel Sambuc int test() {
22*f4a2713aSLionel Sambuc   foo();
23*f4a2713aSLionel Sambuc   foo2();
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc   return nux + nux2;
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc // Function becomes a variable.
30*f4a2713aSLionel Sambuc void foo3() __asm__("var");
31*f4a2713aSLionel Sambuc 
test2()32*f4a2713aSLionel Sambuc void test2() {
33*f4a2713aSLionel Sambuc   foo3();
34*f4a2713aSLionel Sambuc }
35*f4a2713aSLionel Sambuc int foo4 __asm__("var") = 4;
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc // Variable becomes a function
39*f4a2713aSLionel Sambuc extern int foo5 __asm__("var2");
40*f4a2713aSLionel Sambuc 
test3()41*f4a2713aSLionel Sambuc void test3() {
42*f4a2713aSLionel Sambuc   foo5 = 1;
43*f4a2713aSLionel Sambuc }
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc void foo6() __asm__("var2");
foo6()46*f4a2713aSLionel Sambuc void foo6() {
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc int foo7 __asm__("foo7") __attribute__((used));
52*f4a2713aSLionel Sambuc float foo8 __asm__("foo7") = 42;
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc // PR4412
55*f4a2713aSLionel Sambuc int func(void);
56*f4a2713aSLionel Sambuc extern int func (void) __asm__ ("FUNC");
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc // CHECK: @FUNC
func(void)59*f4a2713aSLionel Sambuc int func(void) {
60*f4a2713aSLionel Sambuc   return 42;
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc // CHECK: @_Z4foo9Dv4_f
64*f4a2713aSLionel Sambuc typedef __attribute__(( vector_size(16) )) float float4;
foo9(float4 f)65*f4a2713aSLionel Sambuc void __attribute__((__overloadable__)) foo9(float4 f) {}
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc // Intrinsic calls.
68*f4a2713aSLionel Sambuc extern int llvm_cas(volatile int*, int, int)
69*f4a2713aSLionel Sambuc   __asm__("llvm.atomic.cmp.swap.i32.p0i32");
70*f4a2713aSLionel Sambuc 
foo10(volatile int * add,int from,int to)71*f4a2713aSLionel Sambuc int foo10(volatile int* add, int from, int to) {
72*f4a2713aSLionel Sambuc   // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p0i32
73*f4a2713aSLionel Sambuc   return llvm_cas(add, from, to);
74*f4a2713aSLionel Sambuc }
75