| 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_ESCHEWS_SET_OPTIONS |
| 9 |
static void set_options (gcc_jit_context *ctxt, const char *argv0) |
| 10 |
{ |
| 11 |
// Set "-O3". |
| 12 |
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3); |
| 13 |
} |
| 14 |
|
| 15 |
#define TEST_COMPILING_TO_FILE |
| 16 |
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER |
| 17 |
#define OUTPUT_FILENAME "output-of-test-restrict-attribute.c.s" |
| 18 |
#include "harness.h" |
| 19 |
|
| 20 |
void |
| 21 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 22 |
{ |
| 23 |
/* Let's try to inject the equivalent of: |
| 24 |
void t(int *__restrict__ a, int *__restrict__ b, char *__restrict__ c) { |
| 25 |
*a += *c; |
| 26 |
*b += *c; |
| 27 |
} |
| 28 |
*/ |
| 29 |
gcc_jit_type *int_type = |
| 30 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 31 |
gcc_jit_type *pint_type = gcc_jit_type_get_pointer(int_type); |
| 32 |
gcc_jit_type *pint_restrict_type = gcc_jit_type_get_restrict(pint_type); |
| 33 |
|
| 34 |
gcc_jit_type *void_type = |
| 35 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); |
| 36 |
|
| 37 |
gcc_jit_param *a = |
| 38 |
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "a"); |
| 39 |
gcc_jit_param *b = |
| 40 |
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "b"); |
| 41 |
gcc_jit_param *c = |
| 42 |
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "c"); |
| 43 |
gcc_jit_param *params[3] = {a, b, c}; |
| 44 |
|
| 45 |
gcc_jit_function *func_t = |
| 46 |
gcc_jit_context_new_function (ctxt, NULL, |
| 47 |
GCC_JIT_FUNCTION_EXPORTED, |
| 48 |
void_type, |
| 49 |
"t", |
| 50 |
3, params, |
| 51 |
0); |
| 52 |
|
| 53 |
gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL); |
| 54 |
|
| 55 |
/* *a += *c; */ |
| 56 |
gcc_jit_block_add_assignment_op ( |
| 57 |
block, NULL, |
| 58 |
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (a), NULL), |
| 59 |
GCC_JIT_BINARY_OP_PLUS, |
| 60 |
gcc_jit_lvalue_as_rvalue ( |
| 61 |
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL))); |
| 62 |
/* *b += *c; */ |
| 63 |
gcc_jit_block_add_assignment_op ( |
| 64 |
block, NULL, |
| 65 |
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (b), NULL), |
| 66 |
GCC_JIT_BINARY_OP_PLUS, |
| 67 |
gcc_jit_lvalue_as_rvalue ( |
| 68 |
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL))); |
| 69 |
|
| 70 |
gcc_jit_block_end_with_void_return (block, NULL); |
| 71 |
} |
| 72 |
|
| 73 |
/* { dg-final { jit-verify-output-file-was-created "" } } */ |
| 74 |
/* { dg-final { jit-verify-assembler-output "addl\\s+%eax,\\s+(%rdi) |
| 75 |
\\s+addl\\s+%eax,\\s+(%rsi)" } } */ |