1 /* { dg-do compile { target x86_64-*-* } } */
8 #define TEST_ESCHEWS_SET_OPTIONS
9 static void set_options (gcc_jit_context
*ctxt
, const char *argv0
)
12 gcc_jit_context_set_int_option(ctxt
, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL
, 2);
15 #define TEST_COMPILING_TO_FILE
16 #define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
17 #define OUTPUT_FILENAME "output-of-test-used-attribute.c.s"
21 create_function (gcc_jit_context
*ctxt
,
22 const char *func_name
,
23 gcc_jit_type
*int_type
,
26 gcc_jit_function
*func
=
27 gcc_jit_context_new_function (ctxt
, NULL
,
28 GCC_JIT_FUNCTION_INTERNAL
,
34 gcc_jit_block
*foo_block
= gcc_jit_function_new_block (func
, NULL
);
35 gcc_jit_block_end_with_return (foo_block
, NULL
,
36 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, returned_value
));
43 create_code (gcc_jit_context
*ctxt
, void *user_data
)
45 /* Let's try to inject the equivalent of:
47 static int not_removed() { return 1; }
48 static int removed() { return 2; }
56 gcc_jit_type
*int_type
=
57 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
59 /* Creating the `not_removed` function. */
60 gcc_jit_function
*not_removed_func
=
61 create_function (ctxt
, "not_removed", int_type
, 1);
62 /* __attribute__ ((used)) */
63 gcc_jit_function_add_attribute(not_removed_func
, GCC_JIT_FN_ATTRIBUTE_USED
);
65 /* Creating the `removed` function. */
66 gcc_jit_function
*removed_func
=
67 create_function (ctxt
, "removed", int_type
, 2);
69 /* Creating the `foo` function. */
70 gcc_jit_function
*foo_func
=
71 gcc_jit_context_new_function (ctxt
, NULL
,
72 GCC_JIT_FUNCTION_EXPORTED
,
78 gcc_jit_block
*foo_block
= gcc_jit_function_new_block (foo_func
, NULL
);
82 gcc_jit_function_new_local (foo_func
, NULL
, int_type
, "x");
85 gcc_jit_block_add_assignment (
88 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 0));
91 gcc_jit_block_add_assignment_op (
94 GCC_JIT_BINARY_OP_PLUS
,
95 gcc_jit_context_new_call (ctxt
, NULL
, removed_func
, 0, NULL
));
97 /* x += not_removed(); */
98 gcc_jit_block_add_assignment_op (
101 GCC_JIT_BINARY_OP_PLUS
,
102 gcc_jit_context_new_call (ctxt
, NULL
, not_removed_func
, 0, NULL
));
105 gcc_jit_block_end_with_return (foo_block
, NULL
, gcc_jit_lvalue_as_rvalue(x
));
108 /* { dg-final { jit-verify-output-file-was-created "" } } */
109 /* Check that the "removed" function was inlined, but not the others */
110 /* { dg-final { jit-verify-assembler-output-not ".type\\s+removed,\\s+@function" { target { ! *-*-darwin* } } } } */
111 /* { dg-final { jit-verify-assembler-output ".type\\s+not_removed,\\s+@function" { target { ! *-*-darwin* } } } } */
112 /* { dg-final { jit-verify-assembler-output ".type\\s+foo,\\s+@function" { target { ! *-*-darwin* } } } } */
114 /* { dg-final { jit-verify-assembler-output-not "\\n_removed:" { target *-*-darwin* } } } */
115 /* { dg-final { jit-verify-assembler-output "\\n_not_removed:" { target *-*-darwin* } } } */
116 /* { dg-final { jit-verify-assembler-output "\\n_foo:" { target *-*-darwin* } } } */