xref: /llvm-project/clang/test/CodeGen/asm-label.c (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1 // RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,LINUX
2 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DARWIN
3 
4 char *strerror(int) asm("alias");
5 int x __asm("foo");
6 
test(void)7 int *test(void) {
8   static int y __asm("bar");
9   strerror(-1);
10   return &y;
11 }
12 
13 // LINUX: @bar = internal global i32 0
14 // LINUX: @foo ={{.*}} global i32 0
15 // LINUX: declare ptr @alias(i32 noundef)
16 
17 // DARWIN: @"\01bar" = internal global i32 0
18 // DARWIN: @"\01foo" ={{.*}} global i32 0
19 // DARWIN: declare ptr @"\01alias"(i32 noundef)
20 
21 extern void *memcpy(void *__restrict, const void *__restrict, unsigned long);
22 extern __typeof(memcpy) memcpy asm("__GI_memcpy");
test_memcpy(void * dst,void * src,unsigned long n)23 void test_memcpy(void *dst, void *src, unsigned long n) {
24   memcpy(dst, src, n);
25 }
26 // CHECK-LABEL: @test_memcpy(
27 // LINUX:         call ptr @__GI_memcpy(
28 // LINUX:       declare ptr @__GI_memcpy(ptr noundef, ptr noundef, i32 noundef)
29 // DARWIN:        call ptr @"\01__GI_memcpy"(
30 // DARWIN:      declare ptr @"\01__GI_memcpy"(ptr noundef, ptr noundef, i32 noundef)
31 
32 long lrint(double x) asm("__GI_lrint");
test_lrint(double x)33 long test_lrint(double x) {
34   return lrint(x);
35 }
36 // CHECK-LABEL: @test_lrint(
37 // LINUX:         call i32 @__GI_lrint(
38 // LINUX:       declare i32 @__GI_lrint(double noundef)
39 // DARWIN:        call i32 @"\01__GI_lrint"(
40 // DARWIN:      declare i32 @"\01__GI_lrint"(double noundef)
41 
42 /// NOTE: GCC can optimize out abs in -O1 or above. Clang does not
43 /// communicate the mapping to the backend so the libcall cannot be eliminated.
44 int abs(int x) asm("__GI_abs");
test_abs(int x)45 long test_abs(int x) {
46   return abs(x);
47 }
48 // CHECK-LABEL: @test_abs(
49 // LINUX:         call i32 @__GI_abs(
50 
51 /// FIXME: test_sin should call real_sin instead.
52 double sin(double x) asm("real_sin");
test_sin(double d)53 double test_sin(double d) { return __builtin_sin(d); }
54 // CHECK-LABEL: @test_sin(
55 // LINUX:         call double @llvm.sin.f64(
56