Clang Project

clang_source_code/test/Sema/riscv-interrupt-attr.c
1// RUN: %clang_cc1 -triple riscv32-unknown-elf -emit-llvm -DCHECK_IR < %s| FileCheck %s
2// RUN: %clang_cc1 -triple riscv64-unknown-elf -emit-llvm -DCHECK_IR < %s| FileCheck %s
3// RUN: %clang_cc1 %s -triple riscv32-unknown-elf -verify -fsyntax-only
4// RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
5
6#if defined(CHECK_IR)
7// CHECK-LABEL:  @foo_user() #0
8// CHECK: ret void
9__attribute__((interrupt("user"))) void foo_user(void) {}
10// CHECK-LABEL:  @foo_supervisor() #1
11// CHECK: ret void
12__attribute__((interrupt("supervisor"))) void foo_supervisor(void) {}
13// CHECK-LABEL:  @foo_machine() #2
14// CHECK: ret void
15__attribute__((interrupt("machine"))) void foo_machine(void) {}
16// CHECK-LABEL:  @foo_default() #2
17// CHECK: ret void
18__attribute__((interrupt())) void foo_default(void) {}
19// CHECK-LABEL:  @foo_default2() #2
20// CHECK: ret void
21__attribute__((interrupt())) void foo_default2(void) {}
22// CHECK: attributes #0
23// CHECK: "interrupt"="user"
24// CHECK: attributes #1
25// CHECK: "interrupt"="supervisor"
26// CHECK: attributes #2
27// CHECK: "interrupt"="machine"
28#else
29struct a { int b; };
30
31struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' attribute only applies to functions}}
32
33__attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning {{'interrupt' attribute argument not supported: USER}}
34
35__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error {{'interrupt' attribute takes no more than 1 argument}}
36
37__attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have a 'void' return type}}
38
39__attribute__((interrupt())) void foo4();
40__attribute__((interrupt())) void foo4() {};
41
42__attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have no parameters}}
43
44__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
45  // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
46
47__attribute__((interrupt, interrupt)) void foo7(void) {} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
48                                                     // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
49
50__attribute__((interrupt(""))) void foo8(void) {} // expected-warning {{'interrupt' attribute argument not supported}}
51
52__attribute__((interrupt("user"))) void foo9(void);
53__attribute__((interrupt("supervisor"))) void foo9(void);
54__attribute__((interrupt("machine"))) void foo9(void);
55
56__attribute__((interrupt("user"))) void foo10(void) {}
57__attribute__((interrupt("supervisor"))) void foo11(void) {}
58__attribute__((interrupt("machine"))) void foo12(void) {}
59__attribute__((interrupt())) void foo13(void) {}
60__attribute__((interrupt)) void foo14(void) {}
61#endif
62
63