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 }
14
15 #define TEST_COMPILING_TO_FILE
16 #define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
17 #define OUTPUT_FILENAME "output-of-test-setting-alignment.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 int foo __attribute__((aligned (8)));
25
26 int main (void) {
27 int bar __attribute__((aligned (16)));
28 }
29 */
30 gcc_jit_type *int_type =
31 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
32 gcc_jit_lvalue *foo =
33 gcc_jit_context_new_global (
34 ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo");
35 gcc_jit_lvalue_set_alignment(foo, 8);
36
37 gcc_jit_field *field = gcc_jit_context_new_field (ctxt,
38 NULL,
39 int_type,
40 "a");
41 gcc_jit_struct *struct_type =
42 gcc_jit_context_new_struct_type(ctxt, NULL, "Type", 1, &field);
43 gcc_jit_function *func_main =
44 gcc_jit_context_new_function (ctxt, NULL,
45 GCC_JIT_FUNCTION_EXPORTED,
46 int_type,
47 "main",
48 0, NULL,
49 0);
50 gcc_jit_lvalue *bar =
51 gcc_jit_function_new_local (
52 func_main, NULL,
53 gcc_jit_struct_as_type (struct_type),
54 "bar");
55 CHECK_VALUE (gcc_jit_lvalue_get_alignment (bar), 0);
56 gcc_jit_lvalue_set_alignment (bar, 16);
57 CHECK_VALUE (gcc_jit_lvalue_get_alignment (bar), 16);
58 gcc_jit_block *block = gcc_jit_function_new_block (func_main, NULL);
59 gcc_jit_rvalue *return_value =
60 gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue_access_field (bar, NULL, field));
61 gcc_jit_block_end_with_return (block, NULL, return_value);
62 }
63
64 /* { dg-final { jit-verify-output-file-was-created "" } } */
65 /* { dg-final { jit-verify-assembler-output ".comm foo,4,8" } } */
66 /* { dg-final { jit-verify-assembler-output "movl -16\\\(%rbp\\\), %eax" } } */