libgomp: Document 'GOMP_teams4'
[official-gcc.git] / gcc / testsuite / jit.dg / test-used-attribute.c
blob446c5c5c31b2f22bb01afa20db03c992818a8f96
1 /* { dg-do compile { target x86_64-*-* } } */
3 #include <stdlib.h>
4 #include <stdio.h>
6 #include "libgccjit.h"
8 #define TEST_ESCHEWS_SET_OPTIONS
9 static void set_options (gcc_jit_context *ctxt, const char *argv0)
11 // Set "-O2".
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"
18 #include "harness.h"
20 gcc_jit_function*
21 create_function (gcc_jit_context *ctxt,
22 const char *func_name,
23 gcc_jit_type *int_type,
24 int returned_value)
26 gcc_jit_function *func =
27 gcc_jit_context_new_function (ctxt, NULL,
28 GCC_JIT_FUNCTION_INTERNAL,
29 int_type,
30 func_name,
31 0, NULL,
32 0);
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));
38 return func;
42 void
43 create_code (gcc_jit_context *ctxt, void *user_data)
45 /* Let's try to inject the equivalent of:
46 __attribute__((used))
47 static int not_removed() { return 1; }
48 static int removed() { return 2; }
49 int foo() {
50 int x = 0;
51 x += not_removed();
52 x += removed();
53 return x;
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,
73 int_type,
74 "foo",
75 0, NULL,
76 0);
78 gcc_jit_block *foo_block = gcc_jit_function_new_block (foo_func, NULL);
80 /* Build locals: */
81 gcc_jit_lvalue *x =
82 gcc_jit_function_new_local (foo_func, NULL, int_type, "x");
84 /* int x = 0; */
85 gcc_jit_block_add_assignment (
86 foo_block, NULL,
88 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0));
90 /* x += removed(); */
91 gcc_jit_block_add_assignment_op (
92 foo_block, NULL,
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 (
99 foo_block, NULL,
101 GCC_JIT_BINARY_OP_PLUS,
102 gcc_jit_context_new_call (ctxt, NULL, not_removed_func, 0, NULL));
104 /* return x; */
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* } } } */