Debian Codegraph @

gcc/testsuite/jit.dg/test-variable-attribute.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_COMPILING_TO_FILE
9 #define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
10 #define OUTPUT_FILENAME "output-of-test-variable-attribute.c.s"
11 #include "harness.h"
12
13 void
14 create_code (gcc_jit_context *ctxt, void *user_data)
15 {
16 /* Let's try to inject the equivalent of:
17
18 int PRIVATE __attribute__ ((visibility ("hidden"))) = 42;
19 int PUBLIC = 12;
20 */
21 gcc_jit_type *int_type =
22 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
23
24 /* Creating the `PRIVATE` variable. */
25 gcc_jit_lvalue *private = gcc_jit_context_new_global (ctxt,
26 NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "PRIVATE");
27 gcc_jit_lvalue_add_string_attribute (private,
28 GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY, "hidden");
29 gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int (
30 ctxt, int_type, 42);
31 gcc_jit_global_set_initializer_rvalue (private, rval);
32
33 /* Creating the `PUBLIC` variable. */
34 gcc_jit_lvalue *public = gcc_jit_context_new_global (ctxt,
35 NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "PUBLIC");
36 gcc_jit_rvalue *rval2 = gcc_jit_context_new_rvalue_from_int (
37 ctxt, int_type, 12);
38 gcc_jit_global_set_initializer_rvalue (public, rval2);
39 }
40
41 /* { dg-final { jit-verify-output-file-was-created "" } } */
42 /* Check that the attribute was applied correctly */
43 /* { dg-final { jit-verify-assembler-output ".hidden\\s+PRIVATE" { target { ! *-*-darwin* } } } } */
44 /* { dg-final { jit-verify-assembler-output ".private_extern\\s+_PRIVATE" { target *-*-darwin* } } } */
45 /* { dg-final { jit-verify-assembler-output ".globl\\s+_?PRIVATE" } } */
46 /* { dg-final { jit-verify-assembler-output-not ".hidden\\s+PUBLIC" { target { ! *-*-darwin* } } } } */
47 /* { dg-final { jit-verify-assembler-output-not ".private_extern\\s+_PUBLIC" { target *-*-darwin* } } } */
48 /* { dg-final { jit-verify-assembler-output ".globl\\s+_?PUBLIC" } } */