diff options
Diffstat (limited to 'gcc/testsuite/jit.dg')
-rw-r--r-- | gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 | ||||
-rw-r--r-- | gcc/testsuite/jit.dg/test-sizeof.c | 50 |
2 files changed, 60 insertions, 0 deletions
diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h index d09a31e..14a0a32 100644 --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h @@ -353,6 +353,13 @@ /* test-setting-alignment.c: This can't be in the testcases array as it is target-specific. */ +/* test-sizeof.c */ +#define create_code create_code_sizeof +#define verify_code verify_code_sizeof +#include "test-sizeof.c" +#undef create_code +#undef verify_code + /* test-string-literal.c */ #define create_code create_code_string_literal #define verify_code verify_code_string_literal @@ -553,6 +560,9 @@ const struct testcase testcases[] = { {"reflection", create_code_reflection , verify_code_reflection }, + {"sizeof", + create_code_sizeof, + verify_code_sizeof}, {"string_literal", create_code_string_literal, verify_code_string_literal}, diff --git a/gcc/testsuite/jit.dg/test-sizeof.c b/gcc/testsuite/jit.dg/test-sizeof.c new file mode 100644 index 0000000..6aef902 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-sizeof.c @@ -0,0 +1,50 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdint.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 +my_sizeof () +{ + return sizeof(int32_t); +} + */ + gcc_jit_type *int32 = + gcc_jit_context_get_int_type (ctxt, 4, 1); + gcc_jit_type *int_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + + gcc_jit_function *func = + gcc_jit_context_new_function (ctxt, + NULL, + GCC_JIT_FUNCTION_EXPORTED, + int_type, + "my_sizeof", + 0, NULL, 0); + + gcc_jit_block *initial = + gcc_jit_function_new_block (func, "initial"); + + gcc_jit_block_end_with_return(initial, NULL, + gcc_jit_context_new_sizeof(ctxt, int32)); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef int (*my_sizeof_type) (); + CHECK_NON_NULL (result); + my_sizeof_type my_sizeof = + (my_sizeof_type)gcc_jit_result_get_code (result, "my_sizeof"); + CHECK_NON_NULL (my_sizeof); + int val = my_sizeof (); + CHECK_VALUE (val, 4); +} |