Skip to content

Commit 04b67ac

Browse files
committed
libgccjit: Support signed char flag
gcc/jit/ChangeLog: * dummy-frontend.cc (jit_langhook_init): Send flag_signed_char argument to build_common_tree_nodes. gcc/testsuite/ChangeLog: * jit.dg/all-non-failing-tests.h: Add test-signed-char.c. * jit.dg/test-signed-char.c: New test.
1 parent 70ec3d2 commit 04b67ac

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

gcc/jit/dummy-frontend.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ jit_langhook_init (void)
10771077
*gcc::jit::active_playback_ctxt);
10781078
global_dc->set_output_format (std::move (sink));
10791079

1080-
build_common_tree_nodes (false);
1080+
build_common_tree_nodes (flag_signed_char);
10811081

10821082
build_common_builtin_nodes ();
10831083

gcc/testsuite/jit.dg/all-non-failing-tests.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@
373373
/* test-setting-alignment.c: This can't be in the testcases array as it
374374
is target-specific. */
375375

376+
/* test-signed-char.c */
377+
#define create_code create_code_signed_char
378+
#define verify_code verify_code_signed_char
379+
#include "test-signed-char.c"
380+
#undef create_code
381+
#undef verify_code
382+
376383
/* test-sizeof.c */
377384
#define create_code create_code_sizeof
378385
#define verify_code verify_code_sizeof
@@ -586,6 +593,9 @@ const struct testcase testcases[] = {
586593
{"reflection",
587594
create_code_reflection ,
588595
verify_code_reflection },
596+
{"signed-char",
597+
create_code_signed_char,
598+
verify_code_signed_char},
589599
{"sizeof",
590600
create_code_sizeof,
591601
verify_code_sizeof},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <stddef.h>
4+
5+
#include "libgccjit.h"
6+
7+
#include "harness.h"
8+
9+
void
10+
create_code (gcc_jit_context *ctxt, void *user_data)
11+
{
12+
/* Let's try to inject the equivalent of:
13+
int test_signed_char ()
14+
{
15+
char val = -2;
16+
return (int) val;
17+
}
18+
*/
19+
gcc_jit_type *char_type =
20+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR);
21+
gcc_jit_type *int_type =
22+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
23+
24+
gcc_jit_function *test_fn =
25+
gcc_jit_context_new_function (ctxt, NULL,
26+
GCC_JIT_FUNCTION_EXPORTED,
27+
int_type,
28+
"test_signed_char",
29+
0, NULL,
30+
0);
31+
32+
gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry");
33+
34+
gcc_jit_rvalue *val = gcc_jit_context_new_rvalue_from_int (ctxt,
35+
char_type, -2);
36+
gcc_jit_rvalue *return_value = gcc_jit_context_new_cast (
37+
ctxt, NULL, val, int_type);
38+
39+
gcc_jit_block_end_with_return (block, NULL, return_value);
40+
}
41+
42+
void
43+
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
44+
{
45+
CHECK_NON_NULL (result);
46+
47+
typedef int (*fn_type) ();
48+
fn_type test_signed_char =
49+
(fn_type)gcc_jit_result_get_code (result, "test_signed_char");
50+
CHECK_NON_NULL (test_signed_char);
51+
CHECK_VALUE (test_signed_char (), -2);
52+
}

0 commit comments

Comments
 (0)