1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_trampoline_setup |
3 | |
4 | #include <stdio.h> |
5 | #include <string.h> |
6 | #include <stdint.h> |
7 | |
8 | /* |
9 | * Tests nested functions |
10 | * The ppc compiler generates a call to __trampoline_setup |
11 | * The i386 and x86_64 compilers generate a call to ___enable_execute_stack |
12 | */ |
13 | |
14 | /* |
15 | * Note that, nested functions are not ISO C and are not supported in Clang. |
16 | */ |
17 | |
18 | #if !defined(__clang__) |
19 | |
20 | typedef int (*nested_func_t)(int x); |
21 | |
22 | nested_func_t proc; |
23 | |
24 | int main() { |
25 | /* Some locals */ |
26 | int c = 10; |
27 | int d = 7; |
28 | |
29 | /* Define a nested function: */ |
30 | int bar(int x) { return x*5 + c*d; }; |
31 | |
32 | /* Assign global to point to nested function |
33 | * (really points to trampoline). */ |
34 | proc = bar; |
35 | |
36 | /* Invoke nested function: */ |
37 | c = 4; |
38 | if ( (*proc)(3) != 43 ) |
39 | return 1; |
40 | d = 5; |
41 | if ( (*proc)(4) != 40 ) |
42 | return 1; |
43 | |
44 | /* Success. */ |
45 | return 0; |
46 | } |
47 | |
48 | #else |
49 | |
50 | int main() { |
51 | printf(format: "skipped\n" ); |
52 | return 0; |
53 | } |
54 | |
55 | #endif |
56 | |