aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/jit.dg
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-01-12 17:14:02 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-01-12 17:14:02 +0000
commit791cfef8e7553e4939a1ed095e25414f6dc713d6 (patch)
tree062ae8773efd3200e81a237028025864147648c8 /gcc/testsuite/jit.dg
parent6c0fcb81dad4c8f2f9c687a40627db0442a475f4 (diff)
downloadgcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.zip
gcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.tar.gz
gcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.tar.bz2
jit: API change to gcc_jit_context_new_global
gcc/jit/ChangeLog: * docs/cp/topics/expressions.rst (Global variables): Add enum gcc_jit_global_kind param to gccjit::context::new_global. * docs/topics/expressions.rst (Global variables): Likewise. Document the new enum. * docs/topics/results.rst (Compilation results): Document globals-handling. * dummy-frontend.c (jit_langhook_write_globals): Call into the playback context's write_global_decls_1 and write_global_decls_2 before and after calling symtab->finalize_compilation_unit (). * jit-playback.c: Include "debug.h". (gcc::jit::playback::context::new_global): Add "kind" param and use it to set TREE_PUBLIC, TREE_STATIC and DECL_EXTERNAL on the underlying VAR_DECL. Call varpool_node::get_create on the VAR_DECL, and add it to m_globals. (gcc::jit::playback::context::write_global_decls_1): New function. (gcc::jit::playback::context::write_global_decls_2): New function. * jit-playback.h (gcc::jit::playback::context::context): Call create on m_globals. (gcc::jit::playback::context::new_global): Add "kind" param. (gcc::jit::playback::context::write_global_decls_1): New function. (gcc::jit::playback::context::write_global_decls_2): New function. (gcc::jit::playback::context::m_globals): New field. * jit-recording.c (gcc::jit::recording::context::context): Initialize m_globals. (gcc::jit::recording::context::new_global): Add param "kind". Add the new global to m_globals. (gcc::jit::recording::context::dump_to_file): Dump the globals. (gcc::jit::recording::global::replay_into): Add field m_kind. (gcc::jit::recording::global::write_to_dump): New override. * jit-recording.h (gcc::jit::recording::context::new_global): Add param "kind". (gcc::jit::recording::context::m_globals): New field. (gcc::jit::recording::global::global): Add param kind. (gcc::jit::recording::global::write_to_dump): New override. (gcc::jit::recording::global::m_kind): New field. * jit-result.c (gcc::jit::result::get_global): New function. * jit-result.h (gcc::jit::result::get_global): New function. * libgccjit++.h (gccjit::context::new_global): Add "kind" param. * libgccjit.c (gcc_jit_context_new_global): Likewise. (gcc_jit_result_get_global): New API entrypoint. * libgccjit.h (gcc_jit_result_get_global): New API entrypoint. (enum gcc_jit_global_kind): New enum. (gcc_jit_context_new_global): API change: add "kind" param. * libgccjit.map (gcc_jit_result_get_global): New symbol. gcc/testsuite/ChangeLog: * jit.dg/test-array-as-pointer.c (create_code): Update call to gcc_jit_context_new_global by setting "kind" to GCC_JIT_GLOBAL_IMPORTED. * jit.dg/test-error-array-as-pointer.c: Likewise. * jit.dg/test-expressions.c (make_test_of_get_address): Likewise. * jit.dg/test-fuzzer.c (make_random_global): Likewise, but setting kind to GCC_JIT_GLOBAL_EXPORTED. * jit.dg/test-using-global.c (the_global): Rename to... (imported_global): ...this. (create_code): Update to test the three kinds of global. (verify_code): Likewise. From-SVN: r219480
Diffstat (limited to 'gcc/testsuite/jit.dg')
-rw-r--r--gcc/testsuite/jit.dg/test-array-as-pointer.c3
-rw-r--r--gcc/testsuite/jit.dg/test-error-array-as-pointer.c5
-rw-r--r--gcc/testsuite/jit.dg/test-expressions.c1
-rw-r--r--gcc/testsuite/jit.dg/test-fuzzer.c1
-rw-r--r--gcc/testsuite/jit.dg/test-using-global.c87
5 files changed, 80 insertions, 17 deletions
diff --git a/gcc/testsuite/jit.dg/test-array-as-pointer.c b/gcc/testsuite/jit.dg/test-array-as-pointer.c
index 1a240ac..6b1f9ad 100644
--- a/gcc/testsuite/jit.dg/test-array-as-pointer.c
+++ b/gcc/testsuite/jit.dg/test-array-as-pointer.c
@@ -62,7 +62,8 @@ create_code (gcc_jit_context *ctxt, void *user_data)
0);
gcc_jit_lvalue *buffer =
- gcc_jit_context_new_global (ctxt, NULL, buf_type, "test_buffer");
+ gcc_jit_context_new_global (ctxt, NULL, GCC_JIT_GLOBAL_IMPORTED,
+ buf_type, "test_buffer");
gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry");
diff --git a/gcc/testsuite/jit.dg/test-error-array-as-pointer.c b/gcc/testsuite/jit.dg/test-error-array-as-pointer.c
index cd2b7f8..d2c07b3 100644
--- a/gcc/testsuite/jit.dg/test-error-array-as-pointer.c
+++ b/gcc/testsuite/jit.dg/test-error-array-as-pointer.c
@@ -62,7 +62,10 @@ create_code (gcc_jit_context *ctxt, void *user_data)
0);
gcc_jit_lvalue *buffer =
- gcc_jit_context_new_global (ctxt, NULL, buf_type, "test_buffer");
+ gcc_jit_context_new_global (ctxt, NULL,
+ GCC_JIT_GLOBAL_IMPORTED,
+ buf_type,
+ "test_buffer");
gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry");
diff --git a/gcc/testsuite/jit.dg/test-expressions.c b/gcc/testsuite/jit.dg/test-expressions.c
index 7e33b56..548cfa2 100644
--- a/gcc/testsuite/jit.dg/test-expressions.c
+++ b/gcc/testsuite/jit.dg/test-expressions.c
@@ -884,6 +884,7 @@ make_test_of_get_address (gcc_jit_context *ctxt)
gcc_jit_context_new_global (
ctxt,
NULL,
+ GCC_JIT_GLOBAL_IMPORTED,
int_type,
"test_global");
diff --git a/gcc/testsuite/jit.dg/test-fuzzer.c b/gcc/testsuite/jit.dg/test-fuzzer.c
index b501792..6943d3e 100644
--- a/gcc/testsuite/jit.dg/test-fuzzer.c
+++ b/gcc/testsuite/jit.dg/test-fuzzer.c
@@ -238,6 +238,7 @@ make_random_global (fuzzer *f)
sprintf (global_name, "g%i", f->num_globals);
return gcc_jit_context_new_global (f->ctxt,
get_random_location (f),
+ GCC_JIT_GLOBAL_EXPORTED,
get_random_type (f),
global_name);
}
diff --git a/gcc/testsuite/jit.dg/test-using-global.c b/gcc/testsuite/jit.dg/test-using-global.c
index 3ec949f..8ac9780 100644
--- a/gcc/testsuite/jit.dg/test-using-global.c
+++ b/gcc/testsuite/jit.dg/test-using-global.c
@@ -9,7 +9,7 @@
extern "C" {
#endif
- extern int the_global;
+ extern int imported_global;
#ifdef __cplusplus
}
@@ -19,24 +19,47 @@ void
create_code (gcc_jit_context *ctxt, void *user_data)
{
/* Let's try to inject the equivalent of:
- extern int the_global;
- void
+ int exported_global;
+ extern int imported_global;
+ static int internal_global;
+
+ int
test_using_global (void)
{
- the_global += 1;
+ exported_global += 1;
+ imported_global += 1;
+ internal_global += 1;
+ return internal_global;
}
*/
- gcc_jit_type *void_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_lvalue *exported_global =
+ gcc_jit_context_new_global (ctxt,
+ NULL,
+ GCC_JIT_GLOBAL_EXPORTED,
+ int_type,
+ "exported_global");
+ gcc_jit_lvalue *imported_global =
+ gcc_jit_context_new_global (ctxt,
+ NULL,
+ GCC_JIT_GLOBAL_IMPORTED,
+ int_type,
+ "imported_global");
+ gcc_jit_lvalue *internal_global =
+ gcc_jit_context_new_global (ctxt,
+ NULL,
+ GCC_JIT_GLOBAL_INTERNAL,
+ int_type,
+ "internal_global");
+
/* Build the test_fn. */
gcc_jit_function *test_fn =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_EXPORTED,
- void_type,
+ int_type,
"test_using_global",
0, NULL,
0);
@@ -44,30 +67,64 @@ create_code (gcc_jit_context *ctxt, void *user_data)
gcc_jit_block_add_assignment_op (
block, NULL,
- gcc_jit_context_new_global (ctxt, NULL, int_type, "the_global"),
+ exported_global,
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_context_one (ctxt, int_type));
+ gcc_jit_block_add_assignment_op (
+ block, NULL,
+ imported_global,
+ GCC_JIT_BINARY_OP_PLUS,
+ gcc_jit_context_one (ctxt, int_type));
+ gcc_jit_block_add_assignment_op (
+ block, NULL,
+ internal_global,
GCC_JIT_BINARY_OP_PLUS,
gcc_jit_context_one (ctxt, int_type));
- gcc_jit_block_end_with_void_return (block, NULL);
+ gcc_jit_block_end_with_return (block,
+ NULL,
+ gcc_jit_lvalue_as_rvalue (internal_global));
}
-int the_global;
+int imported_global;
void
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
{
- typedef void (*fn_type) (void);
+ typedef int (*fn_type) (void);
CHECK_NON_NULL (result);
fn_type test_using_global =
(fn_type)gcc_jit_result_get_code (result, "test_using_global");
CHECK_NON_NULL (test_using_global);
- the_global = 42;
+ /* The exported global should be visible. */
+ int *exported_global = (int *)gcc_jit_result_get_global (result, "exported_global");
+ CHECK_NON_NULL (exported_global);
+ /* ...and should be zero-initialized. */
+ CHECK_VALUE (*exported_global, 0);
+
+ /* Set some nonzero values. */
+ *exported_global = 11;
+ imported_global = 42;
+
+ /* The internal global shouldn't be visible. */
+ int *internal_global = (int *)gcc_jit_result_get_global (result, "internal_global");
+ CHECK_VALUE (internal_global, NULL);
/* Call the JIT-generated function. */
- test_using_global ();
+ int call_count = test_using_global ();
+
+ /* Verify that it correctly modified imported_global and exported_global. */
+ CHECK_VALUE (*exported_global, 12);
+ CHECK_VALUE (imported_global, 43);
+ CHECK_VALUE (call_count, 1);
+
+ /* Try calling it again. */
+ call_count = test_using_global ();
- /* Verify that it correctly modified the_global. */
- CHECK_VALUE (the_global, 43);
+ /* Verify the new values. */
+ CHECK_VALUE (*exported_global, 13);
+ CHECK_VALUE (imported_global, 44);
+ CHECK_VALUE (call_count, 2);
}