diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-05-26 09:28:16 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-05-26 18:00:46 -0400 |
commit | bf40f0ba95037f235b007a55a7682646a0578b26 (patch) | |
tree | 7d94d8725092b5961d9d641b62a141da11cc6ad4 /gcc/jit | |
parent | 56f03cd12be26828788a27f6f3c250041a958e45 (diff) | |
download | gcc-bf40f0ba95037f235b007a55a7682646a0578b26.zip gcc-bf40f0ba95037f235b007a55a7682646a0578b26.tar.gz gcc-bf40f0ba95037f235b007a55a7682646a0578b26.tar.bz2 |
jit: fix missing types for builtins [PR 95306]
PR jit/95306 reports that attempts to use builtins
__builtin_sadd_overflow" and "__builtin_memcpy" via
gcc_jit_context_get_builtin_function lead to inscrutable error
messages of the form:
unimplemented primitive type for builtin: 42
and:
unimplemented primitive type for builtin: 38
The root cause is that jit-builtins.c only implements a subset
of the types defined via DEF_PRIMITIVE_TYPE in builtin-types.def.
This patch:
- implements enough types to enable the above two builtins to be
referenced
- documents gcc_jit_context_get_builtin_function, and notes the
limitation that not all types are supported (supporting
some of them would take a lot of extra work)
- improves the error message for the unsupported cases
- adds a testcase for __builtin_memcpy. This required
jit_langhook_global_bindings_p to be implemented (otherwise
the assertion there failed deep inside "expand" on the builtin)
- adds test coverage for the above
gcc/jit/ChangeLog:
PR jit/95306
* docs/topics/functions.rst
(gcc_jit_context_get_builtin_function): Document.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
* dummy-frontend.c (jit_langhook_global_bindings_p): Remove
gcc_unreachable.
* jit-builtins.c (type_names): New array.
(get_string_for_type_id): New function.
(gcc::jit::builtins_manager::make_primitive_type): Show name of
type in error messages. Update cases to reflect the order in
builtin-types.def. Implement cases for BT_INT8, BT_INT16,
BT_UINT8, BT_CONST_PTR, BT_VOLATILE_PTR, BT_INT_PTR, BT_FLOAT_PTR,
BT_CONST_DOUBLE_PTR, BT_SIZE, BT_CONST_SIZE.
gcc/testsuite/ChangeLog:
PR jit/95306
* jit.dg/all-non-failing-tests.h: Add test-builtin-memcpy.c and
test-pr95306-builtin-types.c.
* jit.dg/test-builtin-memcpy.c: New test.
* jit.dg/test-error-gcc_jit_context_get_builtin_function-unimplemented-type.c:
New test.
* jit.dg/test-pr95306-builtin-types.c: New test.
Diffstat (limited to 'gcc/jit')
-rw-r--r-- | gcc/jit/docs/_build/texinfo/libgccjit.texi | 21 | ||||
-rw-r--r-- | gcc/jit/docs/topics/functions.rst | 15 | ||||
-rw-r--r-- | gcc/jit/dummy-frontend.c | 1 | ||||
-rw-r--r-- | gcc/jit/jit-builtins.c | 122 |
4 files changed, 148 insertions, 11 deletions
diff --git a/gcc/jit/docs/_build/texinfo/libgccjit.texi b/gcc/jit/docs/_build/texinfo/libgccjit.texi index 8eed7d2..6114f81 100644 --- a/gcc/jit/docs/_build/texinfo/libgccjit.texi +++ b/gcc/jit/docs/_build/texinfo/libgccjit.texi @@ -7037,7 +7037,26 @@ buffer. @geindex gcc_jit_context_get_builtin_function (C function) @anchor{topics/functions c gcc_jit_context_get_builtin_function}@anchor{df} -@deffn {C Function} gcc_jit_function *gcc_jit_context_get_builtin_function (gcc_jit_context@w{ }*ctxt, const char@w{ }*name) +@deffn {C Function} gcc_jit_function * gcc_jit_context_get_builtin_function (gcc_jit_context@w{ }*ctxt, const char@w{ }*name) + +Get the @ref{29,,gcc_jit_function} for the built-in function with the +given name. For example: + +@example +gcc_jit_function *fn + = gcc_jit_context_get_builtin_function (ctxt, "__builtin_memcpy"); +@end example + +@cartouche +@quotation Note +Due to technical limitations with how libgccjit interacts with +the insides of GCC, not all built-in functions are supported. More +precisely, not all types are supported for parameters of built-in +functions from libgccjit. Attempts to get a built-in function that +uses such a parameter will lead to an error being emitted within +the context. +@end quotation +@end cartouche @end deffn @geindex gcc_jit_function_as_object (C function) diff --git a/gcc/jit/docs/topics/functions.rst b/gcc/jit/docs/topics/functions.rst index 29ce96c..eb40d64 100644 --- a/gcc/jit/docs/topics/functions.rst +++ b/gcc/jit/docs/topics/functions.rst @@ -125,6 +125,21 @@ Functions gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt,\ const char *name) + Get the :type:`gcc_jit_function` for the built-in function with the + given name. For example: + + .. code-block:: c + + gcc_jit_function *fn + = gcc_jit_context_get_builtin_function (ctxt, "__builtin_memcpy"); + + .. note:: Due to technical limitations with how libgccjit interacts with + the insides of GCC, not all built-in functions are supported. More + precisely, not all types are supported for parameters of built-in + functions from libgccjit. Attempts to get a built-in function that + uses such a parameter will lead to an error being emitted within + the context. + .. function:: gcc_jit_object *\ gcc_jit_function_as_object (gcc_jit_function *func) diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c index 956ba62..27fe9d3 100644 --- a/gcc/jit/dummy-frontend.c +++ b/gcc/jit/dummy-frontend.c @@ -230,7 +230,6 @@ jit_langhook_builtin_function (tree decl) static bool jit_langhook_global_bindings_p (void) { - gcc_unreachable (); return true; } diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c index 2ea298b..4842ff3 100644 --- a/gcc/jit/jit-builtins.c +++ b/gcc/jit/jit-builtins.c @@ -245,6 +245,85 @@ builtins_manager::make_builtin_function (enum built_in_function builtin_id) return result; } +/* Build an array of type names for use by get_string_for_type_id. */ + +static const char * const type_names[] = { +#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) #ENUM, +#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) #ENUM, +#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) #ENUM, +#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) #ENUM, +#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) #ENUM, +#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) #ENUM, +#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) #ENUM, +#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6) \ + #ENUM, +#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7) \ + #ENUM, +#define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7, ARG8) \ + #ENUM, +#define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7, ARG8, ARG9) \ + #ENUM, +#define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7, ARG8, ARG9, ARG10) \ + #ENUM, +#define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \ + #ENUM, +#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) #ENUM, +#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) #ENUM, +#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) #ENUM, +#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) #ENUM, +#define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) #ENUM, +#define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ + #ENUM, +#define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6) \ + #ENUM, +#define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ + ARG6, ARG7) \ + #ENUM, +#define DEF_POINTER_TYPE(ENUM, TYPE) #ENUM, + +#include "builtin-types.def" + +#undef DEF_PRIMITIVE_TYPE +#undef DEF_FUNCTION_TYPE_0 +#undef DEF_FUNCTION_TYPE_1 +#undef DEF_FUNCTION_TYPE_2 +#undef DEF_FUNCTION_TYPE_3 +#undef DEF_FUNCTION_TYPE_4 +#undef DEF_FUNCTION_TYPE_5 +#undef DEF_FUNCTION_TYPE_6 +#undef DEF_FUNCTION_TYPE_7 +#undef DEF_FUNCTION_TYPE_8 +#undef DEF_FUNCTION_TYPE_9 +#undef DEF_FUNCTION_TYPE_10 +#undef DEF_FUNCTION_TYPE_11 +#undef DEF_FUNCTION_TYPE_VAR_0 +#undef DEF_FUNCTION_TYPE_VAR_1 +#undef DEF_FUNCTION_TYPE_VAR_2 +#undef DEF_FUNCTION_TYPE_VAR_3 +#undef DEF_FUNCTION_TYPE_VAR_4 +#undef DEF_FUNCTION_TYPE_VAR_5 +#undef DEF_FUNCTION_TYPE_VAR_6 +#undef DEF_FUNCTION_TYPE_VAR_7 +#undef DEF_POINTER_TYPE +}; + +/* Get a string for TYPE_ID suitable for use in logs and error messages + (e.g. "BT_PID"). */ + +static const char * +get_string_for_type_id (enum jit_builtin_type type_id) +{ + gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0])); + return type_names[type_id]; +} + /* Get the recording::type for a given type of builtin function, by ID, creating it if it doesn't already exist. */ @@ -383,7 +462,8 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id) default: // only some of these types are implemented so far: m_ctxt->add_error (NULL, - "unimplemented primitive type for builtin: %d", type_id); + "unimplemented primitive type for builtin (type: %s)", + get_string_for_type_id (type_id)); return NULL; case BT_VOID: return m_ctxt->get_type (GCC_JIT_TYPE_VOID); @@ -395,10 +475,11 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id) case BT_LONGLONG: return m_ctxt->get_type (GCC_JIT_TYPE_LONG_LONG); case BT_ULONGLONG: return m_ctxt->get_type (GCC_JIT_TYPE_UNSIGNED_LONG_LONG); - // case BT_INT128: - // case BT_UINT128: // case BT_INTMAX: // case BT_UINTMAX: + case BT_INT8: return m_ctxt->get_int_type (1, true); + case BT_INT16: return m_ctxt->get_int_type (2, true); + case BT_UINT8: return m_ctxt->get_int_type (1, false); case BT_UINT16: return m_ctxt->get_int_type (2, false); case BT_UINT32: return m_ctxt->get_int_type (4, false); case BT_UINT64: return m_ctxt->get_int_type (8, false); @@ -407,6 +488,13 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id) case BT_FLOAT: return m_ctxt->get_type (GCC_JIT_TYPE_FLOAT); case BT_DOUBLE: return m_ctxt->get_type (GCC_JIT_TYPE_DOUBLE); case BT_LONGDOUBLE: return m_ctxt->get_type (GCC_JIT_TYPE_LONG_DOUBLE); + // case BT_FLOAT16: + // case BT_FLOAT32: + // case BT_FLOAT64: + // case BT_FLOAT128: + // case BT_FLOAT32X: + // case BT_FLOAT64X: + // case BT_FLOAT128X: case BT_COMPLEX_FLOAT: return m_ctxt->get_type (GCC_JIT_TYPE_COMPLEX_FLOAT); case BT_COMPLEX_DOUBLE: @@ -415,18 +503,33 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id) return m_ctxt->get_type (GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE); case BT_PTR: return m_ctxt->get_type (GCC_JIT_TYPE_VOID_PTR); case BT_FILEPTR: return m_ctxt->get_type (GCC_JIT_TYPE_FILE_PTR); - // case BT_CONST: - // case BT_VOLATILE_PTR: + // case BT_CONST_TM_PTR: + // case BT_FENV_T_PTR: + // case BT_CONST_FENV_T_PTR: + // case BT_FEXCEPT_T_PTR: + // case BT_CONST_FEXCEPT_T_PTR: + case BT_CONST_PTR: + return m_ctxt->get_type (GCC_JIT_TYPE_VOID)->get_const ()->get_pointer (); + case BT_VOLATILE_PTR: + return (m_ctxt->get_type (GCC_JIT_TYPE_VOID)->get_volatile () + ->get_pointer ()); // case BT_CONST_VOLATILE_PTR: // case BT_PTRMODE: - // case BT_INT_PTR: - // case BT_FLOAT_PTR: + case BT_INT_PTR: + return m_ctxt->get_type (GCC_JIT_TYPE_INT)->get_pointer (); + case BT_FLOAT_PTR: + return m_ctxt->get_type (GCC_JIT_TYPE_FLOAT)->get_pointer (); case BT_DOUBLE_PTR: return m_ctxt->get_type (GCC_JIT_TYPE_DOUBLE)->get_pointer (); - // case BT_CONST_DOUBLE_PTR: + case BT_CONST_DOUBLE_PTR: + return (m_ctxt->get_type (GCC_JIT_TYPE_DOUBLE)->get_const () + ->get_pointer ()); // case BT_LONGDOUBLE_PTR: // case BT_PID: - // case BT_SIZE: + case BT_SIZE: + return m_ctxt->get_type (GCC_JIT_TYPE_SIZE_T); + case BT_CONST_SIZE: + return m_ctxt->get_type (GCC_JIT_TYPE_SIZE_T)->get_const (); // case BT_SSIZE: // case BT_WINT: // case BT_STRING: @@ -441,6 +544,7 @@ builtins_manager::make_primitive_type (enum jit_builtin_type type_id) // case BT_I4: // case BT_I8: // case BT_I16: + // case BT_PTR_CONST_STRING: } } |