Debian Codegraph @

gcc/testsuite/jit.dg/test-target-builtins.c

raw
1 /* { dg-do compile { target x86_64-*-* } } */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include "libgccjit.h"
7
8 #define TEST_PROVIDES_MAIN
9 #include "harness.h"
10
11 void
12 create_code (gcc_jit_context *ctxt, void *user_data)
13 {
14 CHECK_NON_NULL (gcc_jit_context_get_target_builtin_function (ctxt, "__builtin_ia32_xgetbv"));
15 gcc_jit_function *builtin_eh_pointer = gcc_jit_context_get_target_builtin_function (ctxt, "__builtin_eh_pointer");
16 CHECK_NON_NULL (builtin_eh_pointer);
17
18 gcc_jit_type *int_type =
19 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
20 gcc_jit_type *void_ptr =
21 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR);
22 gcc_jit_function *func_main =
23 gcc_jit_context_new_function (ctxt, NULL,
24 GCC_JIT_FUNCTION_EXPORTED,
25 int_type,
26 "main",
27 0, NULL,
28 0);
29 gcc_jit_rvalue *zero = gcc_jit_context_zero (ctxt, int_type);
30 gcc_jit_block *block = gcc_jit_function_new_block (func_main, NULL);
31 gcc_jit_lvalue *variable = gcc_jit_function_new_local(func_main, NULL, void_ptr, "variable");
32 gcc_jit_block_add_assignment (block, NULL, variable,
33 gcc_jit_context_new_call (ctxt, NULL, builtin_eh_pointer, 1, &zero));
34 gcc_jit_block_end_with_return (block, NULL, zero);
35 }
36
37 void
38 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
39 {
40 CHECK_NON_NULL (result);
41 }
42
43 int
44 main (int argc, char **argv)
45 {
46 /* This is the same as the main provided by harness.h, but it first create a dummy context and compile
47 in order to add the target builtins to libgccjit's internal state. */
48 gcc_jit_context *ctxt;
49 ctxt = gcc_jit_context_acquire ();
50 if (!ctxt)
51 {
52 fail ("gcc_jit_context_acquire failed");
53 return -1;
54 }
55 gcc_jit_result *result;
56 result = gcc_jit_context_compile (ctxt);
57 gcc_jit_result_release (result);
58 gcc_jit_context_release (ctxt);
59
60 int i;
61
62 for (i = 1; i <= 5; i++)
63 {
64 snprintf (test, sizeof (test),
65 "%s iteration %d of %d",
66 extract_progname (argv[0]),
67 i, 5);
68
69 //printf ("ITERATION %d\n", i);
70 test_jit (argv[0], NULL);
71 //printf ("\n");
72 }
73
74 totals ();
75
76 return 0;
77 }