| 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-weak-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 |
__attribute__ ((weak)) |
| 19 |
void f () {} |
| 20 |
*/ |
| 21 |
gcc_jit_type *void_type = |
| 22 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); |
| 23 |
|
| 24 |
/* Creating the `f` function. */ |
| 25 |
gcc_jit_function *f_func = |
| 26 |
gcc_jit_context_new_function (ctxt, NULL, |
| 27 |
GCC_JIT_FUNCTION_EXPORTED, |
| 28 |
void_type, |
| 29 |
"f", |
| 30 |
0, NULL, |
| 31 |
0); |
| 32 |
gcc_jit_function_add_attribute(f_func, GCC_JIT_FN_ATTRIBUTE_WEAK); |
| 33 |
|
| 34 |
/* void f () {} */ |
| 35 |
gcc_jit_block *block = gcc_jit_function_new_block (f_func, NULL); |
| 36 |
gcc_jit_block_end_with_void_return (block, NULL); |
| 37 |
} |
| 38 |
|
| 39 |
/* { dg-final { jit-verify-output-file-was-created "" } } */ |
| 40 |
/* Check that the attribute was applied correctly */ |
| 41 |
/* { dg-final { jit-verify-assembler-output ".weak\\s+f" { target { ! *-*-darwin* } } } } */ |
| 42 |
/* { dg-final { jit-verify-assembler-output ".weak_definition\\s+_f" { target *-*-darwin* } } } */ |