Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions gcc/testsuite/jit.dg/test-alias-attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* { dg-do compile { target x86_64-*-* } } */

#include <stdlib.h>
#include <stdio.h>

#include "libgccjit.h"

#define TEST_COMPILING_TO_FILE
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
#define OUTPUT_FILENAME "output-of-test-alias-attribute.c.s"
#include "harness.h"

void
create_code (gcc_jit_context *ctxt, void *user_data)
{
/* Let's try to inject the equivalent of:

void xxx () {}
void f () __attribute__ ((alias ("xxx")));
*/
gcc_jit_type *void_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);

/* Creating the `xxx` function. */
gcc_jit_function *xxx_func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_EXPORTED,
void_type,
"xxx",
0, NULL,
0);

/* Creating the `f` function. */
gcc_jit_function *f_func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_IMPORTED,
void_type,
"f",
0, NULL,
0);
gcc_jit_function_add_string_attribute(f_func, GCC_JIT_FN_ATTRIBUTE_ALIAS, "xxx");

/* void xxx () {} */
gcc_jit_block *block = gcc_jit_function_new_block (xxx_func, NULL);
gcc_jit_block_end_with_void_return (block, NULL);
}

/* { dg-final { jit-verify-output-file-was-created "" } } */
/* Check that the attribute was applied correctly */
/* { dg-final { jit-verify-assembler-output ".set\\s+f,xxx" } } */
153 changes: 153 additions & 0 deletions gcc/testsuite/jit.dg/test-always_inline-attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* { dg-do compile { target x86_64-*-* } } */

#include <stdlib.h>
#include <stdio.h>

#include "libgccjit.h"

#define TEST_ESCHEWS_SET_OPTIONS
static void set_options (gcc_jit_context *ctxt, const char *argv0)
{
// Set "-O0".
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 0);
}

#define TEST_COMPILING_TO_FILE
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
#define OUTPUT_FILENAME "output-of-test-always_inline-attribute.c.s"
#include "harness.h"

gcc_jit_function*
create_function (gcc_jit_context *ctxt,
const char *func_name,
gcc_jit_type *int_type,
gcc_jit_type *pint_type)
{
/* The `a` function argument */
gcc_jit_param *a = gcc_jit_context_new_param (ctxt, NULL, pint_type, "a");
gcc_jit_function *func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_INTERNAL,
int_type,
func_name,
1, &a,
0);

gcc_jit_block *if_cond =
gcc_jit_function_new_block (func, "if_cond");
gcc_jit_block *if_body =
gcc_jit_function_new_block (func, "if_body");
gcc_jit_block *after_if =
gcc_jit_function_new_block (func, "after_if");

/* if (!a) */
gcc_jit_block_end_with_conditional (
if_cond, NULL,
gcc_jit_context_new_comparison (
ctxt, NULL,
GCC_JIT_COMPARISON_EQ,
gcc_jit_param_as_rvalue (a),
gcc_jit_context_null (ctxt, pint_type)),
if_body,
after_if);
/* return -1; */
gcc_jit_block_end_with_return (
if_body, NULL,
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, -1));

/* return *a; */
gcc_jit_block_end_with_return (
after_if, NULL,
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference (
gcc_jit_param_as_rvalue (a), NULL)));

return func;
}


void
create_code (gcc_jit_context *ctxt, void *user_data)
{
/* Let's try to inject the equivalent of:
__attribute__ ((always_inline))
static inline int removed (int *a) {
if (!a) {
return -1;
}
return *a;
}
static int not_removed (int *a) {
if (!a) {
return -1;
}
return *a;
}
int foo () {
int x = 0;
x += removed(NULL);
x += not_removed(NULL);
return x;
}
*/
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
gcc_jit_type *pint_type = gcc_jit_type_get_pointer (int_type);

/* Creating the `removed` function. */
gcc_jit_function *removed_func =
create_function (ctxt, "removed", int_type, pint_type);
/* This one is to declare the function as "inline" */
gcc_jit_function_add_attribute(removed_func, GCC_JIT_FN_ATTRIBUTE_INLINE);
/* __attribute__ ((always_inline)) */
gcc_jit_function_add_attribute(removed_func, GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE);

/* Creating the `not_removed` function. */
gcc_jit_function *not_removed_func =
create_function (ctxt, "not_removed", int_type, pint_type);

/* Creating the `foo` function. */
gcc_jit_function *foo_func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_EXPORTED,
int_type,
"foo",
0, NULL,
0);

gcc_jit_block *foo_block = gcc_jit_function_new_block (foo_func, NULL);

/* Build locals: */
gcc_jit_lvalue *x =
gcc_jit_function_new_local (foo_func, NULL, int_type, "x");

/* int x = 0; */
gcc_jit_block_add_assignment (
foo_block, NULL,
x,
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0));

/* x += removed(NULL); */
gcc_jit_rvalue *null = gcc_jit_context_null (ctxt, pint_type);
gcc_jit_block_add_assignment_op (
foo_block, NULL,
x,
GCC_JIT_BINARY_OP_PLUS,
gcc_jit_context_new_call (ctxt, NULL, removed_func, 1, &null));

/* x += not_removed(NULL); */
gcc_jit_block_add_assignment_op (
foo_block, NULL,
x,
GCC_JIT_BINARY_OP_PLUS,
gcc_jit_context_new_call (ctxt, NULL, not_removed_func, 1, &null));

/* return x; */
gcc_jit_block_end_with_return (foo_block, NULL, gcc_jit_lvalue_as_rvalue(x));
}

/* { dg-final { jit-verify-output-file-was-created "" } } */
/* Check that the "removed" function was inlined, but not the others */
/* { dg-final { jit-verify-assembler-output-not ".type\\s+removed,\\s+@function" } } */
/* { dg-final { jit-verify-assembler-output ".type\\s+not_removed,\\s+@function" } } */
/* { dg-final { jit-verify-assembler-output ".type\\s+foo,\\s+@function" } } */
114 changes: 114 additions & 0 deletions gcc/testsuite/jit.dg/test-noinline-attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* { dg-do compile { target x86_64-*-* } } */

#include <stdlib.h>
#include <stdio.h>

#include "libgccjit.h"

/* We don't want set_options() in harness.h to set -O2 to see that the `noinline`
attribute affects the optimizations. */
#define TEST_ESCHEWS_SET_OPTIONS
static void set_options (gcc_jit_context *ctxt, const char *argv0)
{
// Set "-O2".
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 2);
}

#define TEST_COMPILING_TO_FILE
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
#define OUTPUT_FILENAME "output-of-test-noinline-attribute.c.s"
#include "harness.h"

gcc_jit_function*
create_function (gcc_jit_context *ctxt,
const char *func_name,
gcc_jit_type *int_type,
int returned_value)
{
gcc_jit_function *func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_INTERNAL,
int_type,
func_name,
0, NULL,
0);

gcc_jit_block *foo_block = gcc_jit_function_new_block (func, NULL);
gcc_jit_block_end_with_return (foo_block, NULL,
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, returned_value));

return func;
}


void
create_code (gcc_jit_context *ctxt, void *user_data)
{
/* Let's try to inject the equivalent of:
__attribute__ ((noinline))
static int not_removed() { return 1; }
static int removed() { return 2; }
int foo () {
int x = 0;
x += removed();
x += not_removed();
return x;
}
*/
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);

/* Creating the `not_removed` function. */
gcc_jit_function *not_removed_func =
create_function (ctxt, "not_removed", int_type, 1);
/* __attribute__ ((no_inline)) */
gcc_jit_function_add_attribute(not_removed_func, GCC_JIT_FN_ATTRIBUTE_NOINLINE);

/* Creating the `removed` function. */
gcc_jit_function *removed_func =
create_function (ctxt, "removed", int_type, 2);

/* Creating the `foo` function. */
gcc_jit_function *foo_func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_EXPORTED,
int_type,
"foo",
0, NULL,
0);

gcc_jit_block *foo_block = gcc_jit_function_new_block (foo_func, NULL);

/* Build locals: */
gcc_jit_lvalue *x =
gcc_jit_function_new_local (foo_func, NULL, int_type, "x");

/* int x = 0; */
gcc_jit_block_add_assignment (
foo_block, NULL,
x,
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0));

/* x += removed(); */
gcc_jit_block_add_assignment_op (
foo_block, NULL,
x,
GCC_JIT_BINARY_OP_PLUS,
gcc_jit_context_new_call (ctxt, NULL, removed_func, 0, NULL));

/* x += not_removed(); */
gcc_jit_block_add_assignment_op (
foo_block, NULL,
x,
GCC_JIT_BINARY_OP_PLUS,
gcc_jit_context_new_call (ctxt, NULL, not_removed_func, 0, NULL));

/* return x; */
gcc_jit_block_end_with_return (foo_block, NULL, gcc_jit_lvalue_as_rvalue(x));
}

/* { dg-final { jit-verify-output-file-was-created "" } } */
/* Check that the "removed" function was inlined, but not the others */
/* { dg-final { jit-verify-assembler-output-not ".type\\s+removed,\\s+@function" } } */
/* { dg-final { jit-verify-assembler-output ".type\\s+not_removed,\\s+@function" } } */
/* { dg-final { jit-verify-assembler-output ".type\\s+foo,\\s+@function" } } */
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ void t(int *__restrict__ a, int *__restrict__ b, char *__restrict__ c) {
}

/* { dg-final { jit-verify-output-file-was-created "" } } */
/* { dg-final { jit-verify-assembler-output "addl %eax, (%rdi)
addl %eax, (%rsi)" } } */
/* { dg-final { jit-verify-assembler-output "addl\\s+%eax,\\s+(%rdi)
\\s+addl\\s+%eax,\\s+(%rsi)" } } */
Loading