|
| 1 | +/* { dg-do compile { target x86_64-*-* } } */ |
| 2 | + |
| 3 | +#include <stdlib.h> |
| 4 | +#include <stdio.h> |
| 5 | + |
| 6 | +#include "libgccjit.h" |
| 7 | + |
| 8 | +/* We don't want set_options() in harness.h to set -O3 so our little local |
| 9 | + is optimized away. */ |
| 10 | +#define TEST_ESCHEWS_SET_OPTIONS |
| 11 | +static void set_options (gcc_jit_context *ctxt, const char *argv0) |
| 12 | +{ |
| 13 | + // Set "-O2". |
| 14 | + gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 2); |
| 15 | +} |
| 16 | + |
| 17 | +#define TEST_COMPILING_TO_FILE |
| 18 | +#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER |
| 19 | +#define OUTPUT_FILENAME "output-of-test-cold-attribute.c.s" |
| 20 | +#include "harness.h" |
| 21 | + |
| 22 | +void |
| 23 | +create_code (gcc_jit_context *ctxt, void *user_data) |
| 24 | +{ |
| 25 | + /* Let's try to inject the equivalent of: |
| 26 | +int |
| 27 | +__attribute__ ((cold)) |
| 28 | +t() |
| 29 | +{ |
| 30 | + return -1; |
| 31 | +} |
| 32 | +
|
| 33 | + */ |
| 34 | + gcc_jit_type *int_type = |
| 35 | + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 36 | + |
| 37 | + gcc_jit_function *func_t = |
| 38 | + gcc_jit_context_new_function (ctxt, NULL, |
| 39 | + GCC_JIT_FUNCTION_EXPORTED, |
| 40 | + int_type, |
| 41 | + "t", |
| 42 | + 0, NULL, |
| 43 | + 0); |
| 44 | + gcc_jit_function_add_attribute(func_t, GCC_JIT_FN_ATTRIBUTE_COLD); |
| 45 | + gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL); |
| 46 | + gcc_jit_rvalue *ret = gcc_jit_context_new_rvalue_from_int (ctxt, |
| 47 | + int_type, |
| 48 | + -1); |
| 49 | + |
| 50 | + gcc_jit_block_end_with_return (block, NULL, ret); |
| 51 | +} |
| 52 | + |
| 53 | +/* { dg-final { jit-verify-output-file-was-created "" } } */ |
| 54 | +/* { dg-final { jit-verify-assembler-output "orl" } } */ |
0 commit comments