xref: /aosp_15_r20/external/clang/test/Sema/attr-naked.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -verify -fsyntax-only -triple i686-pc-linux
2*67e74705SXin Li 
3*67e74705SXin Li int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}}
4*67e74705SXin Li 
t0(void)5*67e74705SXin Li __attribute__((naked)) int t0(void) {
6*67e74705SXin Li   __asm__ volatile("mov r0, #0");
7*67e74705SXin Li }
8*67e74705SXin Li 
9*67e74705SXin Li void t1() __attribute__((naked));
10*67e74705SXin Li 
11*67e74705SXin Li void t2() __attribute__((naked(2))); // expected-error {{'naked' attribute takes no arguments}}
12*67e74705SXin Li 
t3()13*67e74705SXin Li __attribute__((naked)) int t3() { // expected-note{{attribute is here}}
14*67e74705SXin Li   return 42; // expected-error{{non-ASM statement in naked function is not supported}}
15*67e74705SXin Li }
16*67e74705SXin Li 
t4()17*67e74705SXin Li __attribute__((naked)) int t4() {
18*67e74705SXin Li   asm("movl $42, %eax");
19*67e74705SXin Li   asm("retl");
20*67e74705SXin Li }
21*67e74705SXin Li 
t5(int x)22*67e74705SXin Li __attribute__((naked)) int t5(int x) {
23*67e74705SXin Li   asm("movl x, %eax");
24*67e74705SXin Li   asm("retl");
25*67e74705SXin Li }
26*67e74705SXin Li 
t6()27*67e74705SXin Li __attribute__((naked)) void t6() {
28*67e74705SXin Li   ;
29*67e74705SXin Li }
30*67e74705SXin Li 
t7()31*67e74705SXin Li __attribute__((naked)) void t7() {
32*67e74705SXin Li   asm("movl $42, %eax");
33*67e74705SXin Li   ;
34*67e74705SXin Li }
35*67e74705SXin Li 
36*67e74705SXin Li extern int x, y;
37*67e74705SXin Li 
t8(int z)38*67e74705SXin Li __attribute__((naked)) void t8(int z) { // expected-note{{attribute is here}}
39*67e74705SXin Li   __asm__ ("movl $42, %1"
40*67e74705SXin Li            : "=r"(x),
41*67e74705SXin Li              "=r"(z) // expected-error{{parameter references not allowed in naked functions}}
42*67e74705SXin Li            );
43*67e74705SXin Li }
44*67e74705SXin Li 
t9(int z)45*67e74705SXin Li __attribute__((naked)) void t9(int z) { // expected-note{{attribute is here}}
46*67e74705SXin Li   __asm__ ("movl %eax, %1"
47*67e74705SXin Li            : : "r"(x),
48*67e74705SXin Li                "r"(z) // expected-error{{parameter references not allowed in naked functions}}
49*67e74705SXin Li            );
50*67e74705SXin Li }
51