jit: fix missing types for builtins [PR 95306]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 26 May 2020 13:28:16 +0000 (09:28 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 26 May 2020 22:00:46 +0000 (18:00 -0400)
commitbf40f0ba95037f235b007a55a7682646a0578b26
tree7d94d8725092b5961d9d641b62a141da11cc6ad4
parent56f03cd12be26828788a27f6f3c250041a958e45
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.
gcc/jit/docs/_build/texinfo/libgccjit.texi
gcc/jit/docs/topics/functions.rst
gcc/jit/dummy-frontend.c
gcc/jit/jit-builtins.c
gcc/testsuite/jit.dg/all-non-failing-tests.h
gcc/testsuite/jit.dg/test-builtin-memcpy.c [new file with mode: 0644]
gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unimplemented-type.c [new file with mode: 0644]
gcc/testsuite/jit.dg/test-pr95306-builtin-types.c [new file with mode: 0644]