blob: 8d1c968b274a17054dc3d9a08a607ebd77a5c856 [file] [log] [blame]
Shih-wei Liao77ed6142010-04-07 12:21:42 -07001/* ===-- trampoline_setup_test.c - Test __trampoline_setup -----------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
7 *
8 * ===----------------------------------------------------------------------===
9 */
10
11
12#include <stdio.h>
13#include <string.h>
14#include <stdint.h>
15#include <sys/mman.h>
16
17/*
18 * Tests nested functions
19 * The ppc compiler generates a call to __trampoline_setup
20 * The i386 and x86_64 compilers generate a call to ___enable_execute_stack
21 */
22
23/*
24 * Note that, nested functions are not ISO C and are not supported in Clang.
25 */
26
27#if !defined(__clang__)
28
29typedef int (*nested_func_t)(int x);
30
31nested_func_t proc;
32
33int main() {
34 /* Some locals */
35 int c = 10;
36 int d = 7;
37
38 /* Define a nested function: */
39 int bar(int x) { return x*5 + c*d; };
40
41 /* Assign global to point to nested function
42 * (really points to trampoline). */
43 proc = bar;
44
45 /* Invoke nested function: */
46 c = 4;
47 if ( (*proc)(3) != 43 )
48 return 1;
49 d = 5;
50 if ( (*proc)(4) != 40 )
51 return 1;
52
53 /* Success. */
54 return 0;
55}
56
57#else
58
59int main() {
60 return 0;
61}
62
63#endif