diff options
author | Petter Tomner <tomner@kth.se> | 2021-11-29 20:44:07 +0100 |
---|---|---|
committer | Petter Tomner <tomner@kth.se> | 2021-12-14 18:18:07 +0100 |
commit | 3736837806fdb26daa51300bee1554bef89db9fe (patch) | |
tree | 874865030ed635b65e50b15bc717891b8047afd6 /gcc/testsuite/jit.dg/test-error-global-already-init.c | |
parent | 1c613165a55b212c59a83796b20a1d555e096504 (diff) | |
download | gcc-3736837806fdb26daa51300bee1554bef89db9fe.zip gcc-3736837806fdb26daa51300bee1554bef89db9fe.tar.gz gcc-3736837806fdb26daa51300bee1554bef89db9fe.tar.bz2 |
Add support for global rvalue initialization and constructors
This patch adds support for initialization of global variables
with rvalues and creating constructors for array, struct and
union types which can be used as rvalues.
Signed-off-by:
2021-12-14 Petter Tomner <tomner@kth.se>
gcc/jit/
* jit-common.h: New enum
* jit-playback.c : Folding an setting intitial
(global_new_decl) : Handle const global generation
(new_global) : New flag
(global_set_init_rvalue) : New
(new_ctor) : New
(new_global_initialized) : Flag
(as_truth_value) : Fold
(new_unary_op) : Fold
(new_binary_op) : Fold
(new_comparison) : Fold
(new_array_access) : Fold
(new_dereference) : Fold
(get_address) : Fold
* jit-playback.h :
(global_set_init_rvalue) : New
(new_ctor) : New
* jit-recording.c :
* jit-recording.h :
(new_global_init_rvalue) : New
(new_ctor) : New
(ctor) : New, inherits rvalue
(global_init_rvalue) : New, inherits memento
(type::is_union) : New
* libgccjit++.h : New entrypoints, see C-header
* libgccjit.c : See .h
* libgccjit.h : New entrypoints
(gcc_jit_context_new_array_constructor) : New
(gcc_jit_context_new_struct_constructor) : New
(gcc_jit_context_new_union_constructor) : New
(gcc_jit_global_set_initializer_rvalue) : New
(LIBGCCJIT_HAVE_CTORS) : New feuture macro
* libgccjit.map : New entrypoints added to ABI 19
* docs/topics/expressions.rst : Updated docs
gcc/testsuite/
* jit.dg/all-non-failing-tests.h: Added two tests
* jit.dg/test-error-ctor-array-wrong-obj.c: New
* jit.dg/test-error-ctor-struct-too-big.c: New
* jit.dg/test-error-ctor-struct-wrong-field-obj.c: New
* jit.dg/test-error-ctor-struct-wrong-type.c: New
* jit.dg/test-error-ctor-struct-wrong-type2.c
* jit.dg/test-error-ctor-union-wrong-field-name.c: New
* jit.dg/test-error-global-already-init.c: New
* jit.dg/test-error-global-common-section.c: New
* jit.dg/test-error-global-init-too-small-array.c: New
* jit.dg/test-error-global-lvalue-init.c: New
* jit.dg/test-error-global-nonconst-init.c: New
* jit.dg/test-global-init-rvalue.c: New
* jit.dg/test-local-init-rvalue.c: New
Diffstat (limited to 'gcc/testsuite/jit.dg/test-error-global-already-init.c')
-rw-r--r-- | gcc/testsuite/jit.dg/test-error-global-already-init.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gcc/testsuite/jit.dg/test-error-global-already-init.c b/gcc/testsuite/jit.dg/test-error-global-already-init.c new file mode 100644 index 0000000..ecead87 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-error-global-already-init.c @@ -0,0 +1,46 @@ +/* + + Test that we can't set the initializer on a global twice. + +*/ + +#include <stdlib.h> +#include <stdio.h> + +#include "libgccjit.h" +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + + gcc_jit_lvalue *bar = gcc_jit_context_new_global ( + ctxt, NULL, + GCC_JIT_GLOBAL_EXPORTED, + int_type, + "global_lvalueinit_int_0"); + + gcc_jit_global_set_initializer_rvalue ( + bar, + gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1)); + gcc_jit_global_set_initializer_rvalue ( + bar, + gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1)); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + /* Ensure that the bad API usage prevents the API giving a bogus + result back. */ + CHECK_VALUE (result, NULL); + + /* Verify that the correct error message was emitted. */ + CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), + "gcc_jit_global_set_initializer_rvalue: global variable " + "already initialized: global_lvalueinit_int_0"); + CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt), + "gcc_jit_global_set_initializer_rvalue: global variable " + "already initialized: global_lvalueinit_int_0"); +} |