1 // REQUIRES: arm-registered-target
2 
3 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -S -o - -emit-llvm -DCALL_LIB -DDEFINE_LIB | FileCheck %s
4 
5 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=full -c -o %t.call_full.bc -DCALL_LIB
6 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=full -c -o %t.define_full.bc -DDEFINE_LIB
7 // RUN: llvm-lto2 run -o %t.lto_full -save-temps %t.call_full.bc %t.define_full.bc \
8 // RUN:  -r %t.call_full.bc,fn,px \
9 // RUN:  -r %t.call_full.bc,fwrite,l \
10 // RUN:  -r %t.call_full.bc,putchar,l \
11 // RUN:  -r %t.call_full.bc,stdout,px \
12 // RUN:  -r %t.define_full.bc,fwrite,px \
13 // RUN:  -r %t.define_full.bc,putchar,px \
14 // RUN:  -r %t.define_full.bc,otherfn,px
15 // RUN: llvm-dis %t.lto_full.0.4.opt.bc -o - | FileCheck %s
16 
17 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=thin -c -o %t.call_thin.bc -DCALL_LIB
18 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
19 // RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc %t.define_thin.bc \
20 // RUN:  -r %t.call_thin.bc,fn,px \
21 // RUN:  -r %t.call_thin.bc,fwrite,l \
22 // RUN:  -r %t.call_thin.bc,putchar,l \
23 // RUN:  -r %t.call_thin.bc,stdout,px \
24 // RUN:  -r %t.define_thin.bc,fwrite,px \
25 // RUN:  -r %t.define_thin.bc,putchar,px \
26 // RUN:  -r %t.define_thin.bc,otherfn,px
27 // RUN: llvm-dis %t.lto_thin.1.4.opt.bc -o - | FileCheck %s
28 
29 // We expect that the fprintf is optimised to fwrite, and the printf is
30 // optimised to putchar. Check that we don't have a mismatch in calling
31 // conventions causing the call to be replaced by a trap.
32 // CHECK-LABEL: define{{.*}}void @fn()
33 // CHECK-NOT: call void @llvm.trap()
34 
35 typedef struct FILE FILE;
36 typedef unsigned int size_t;
37 extern FILE *stdout;
38 extern int fprintf(FILE *, const char *, ...);
39 extern int printf(const char *, ...);
40 extern void otherfn(const void *);
41 
42 #ifdef CALL_LIB
43 
fn()44 void fn() {
45   fprintf(stdout, "hello world");
46   printf("a");
47 }
48 
49 #endif
50 
51 #ifdef DEFINE_LIB
52 
fwrite(const void * ptr,size_t size,size_t nmemb,FILE * stream)53 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
54   otherfn(ptr);
55   return 0;
56 }
57 
putchar(int c)58 int putchar(int c) {
59   otherfn(&c);
60   return 0;
61 }
62 
63 #endif
64