PR lto/84212 - -Wno-* does not disable warnings from -flto link stage
[official-gcc.git] / gcc / testsuite / jit.dg / test-volatile.c
blob3ef3ca5cf4a3b8855577e08611051e6524edd1e7
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "libgccjit.h"
6 #include "harness.h"
8 volatile int the_volatile;
10 void
11 create_code (gcc_jit_context *ctxt, void *user_data)
13 /* Let's try to inject the equivalent of:
14 extern volatile int the_volatile;
16 int
17 test_using_volatile (void)
19 return the_volatile;
22 gcc_jit_type *int_type =
23 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
24 gcc_jit_type *volatile_int_type =
25 gcc_jit_type_get_volatile (int_type);
27 /* Build the test_fn. */
28 gcc_jit_function *test_fn =
29 gcc_jit_context_new_function (ctxt, NULL,
30 GCC_JIT_FUNCTION_EXPORTED,
31 int_type,
32 "test_using_volatile",
33 0, NULL,
34 0);
35 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
36 gcc_jit_lvalue *read_of_the_volatile =
37 gcc_jit_rvalue_dereference (
38 gcc_jit_context_new_rvalue_from_ptr (
39 ctxt,
40 gcc_jit_type_get_pointer (volatile_int_type),
41 (void *)&the_volatile),
42 NULL);
44 gcc_jit_block_end_with_return (
45 block, NULL,
46 gcc_jit_lvalue_as_rvalue (read_of_the_volatile));
49 void
50 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
52 typedef int (*fn_type) (void);
53 CHECK_NON_NULL (result);
55 fn_type test_using_volatile =
56 (fn_type)gcc_jit_result_get_code (result, "test_using_volatile");
57 CHECK_NON_NULL (test_using_volatile);
59 the_volatile = 42;
61 /* Call the JIT-generated function. */
62 test_using_volatile ();
64 CHECK_VALUE (test_using_volatile (), 42);