diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc index 35475b5ad05d7d572ebb95234695fa755605676c..327e8de4f94a9a5c8266e6f777aaec0f5ff36f19 100644 --- a/gcc/jit/dummy-frontend.cc +++ b/gcc/jit/dummy-frontend.cc @@ -1077,7 +1077,7 @@ jit_langhook_init (void) *gcc::jit::active_playback_ctxt); global_dc->set_output_format (std::move (sink)); - build_common_tree_nodes (false); + build_common_tree_nodes (flag_signed_char); build_common_builtin_nodes (); diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h index 32ca70da4374ed2597f8e78481f6c1c6813ae7fb..7b8cf624bbaa00e64ef20734a676fea2cc106271 100644 --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h @@ -373,6 +373,13 @@ /* test-setting-alignment.c: This can't be in the testcases array as it is target-specific. */ +/* test-signed-char.c */ +#define create_code create_code_signed_char +#define verify_code verify_code_signed_char +#include "test-signed-char.c" +#undef create_code +#undef verify_code + /* test-sizeof.c */ #define create_code create_code_sizeof #define verify_code verify_code_sizeof @@ -586,6 +593,9 @@ const struct testcase testcases[] = { {"reflection", create_code_reflection , verify_code_reflection }, + {"signed-char", + create_code_signed_char, + verify_code_signed_char}, {"sizeof", create_code_sizeof, verify_code_sizeof}, diff --git a/gcc/testsuite/jit.dg/test-signed-char.c b/gcc/testsuite/jit.dg/test-signed-char.c new file mode 100644 index 0000000000000000000000000000000000000000..c12b41d92cc3b68d7a643409f86635b47f5b60b3 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-signed-char.c @@ -0,0 +1,52 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stddef.h> + +#include "libgccjit.h" + +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + /* Let's try to inject the equivalent of: + int test_signed_char () + { + char val = -2; + return (int) val; + } + */ + gcc_jit_type *char_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR); + gcc_jit_type *int_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + + gcc_jit_function *test_fn = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + int_type, + "test_signed_char", + 0, NULL, + 0); + + gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry"); + + gcc_jit_rvalue *val = gcc_jit_context_new_rvalue_from_int (ctxt, + char_type, -2); + gcc_jit_rvalue *return_value = gcc_jit_context_new_cast ( + ctxt, NULL, val, int_type); + + gcc_jit_block_end_with_return (block, NULL, return_value); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_NON_NULL (result); + + typedef int (*fn_type) (); + fn_type test_signed_char = + (fn_type)gcc_jit_result_get_code (result, "test_signed_char"); + CHECK_NON_NULL (test_signed_char); + CHECK_VALUE (test_signed_char (), -2); +}