From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 24C4A385801D; Fri, 10 Dec 2021 22:52:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24C4A385801D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5903] jit: set DECL_CONTEXT of RESULT_DECL [PR103562] X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 1e2eee7b29ed2afbc7edea6f3da7e6c8f70b1a4e X-Git-Newrev: a2f4b4b76cdd0a4150e82e69fae4a70c54b523d2 Message-Id: <20211210225257.24C4A385801D@sourceware.org> Date: Fri, 10 Dec 2021 22:52:57 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2021 22:52:57 -0000 https://gcc.gnu.org/g:a2f4b4b76cdd0a4150e82e69fae4a70c54b523d2 commit r12-5903-ga2f4b4b76cdd0a4150e82e69fae4a70c54b523d2 Author: David Malcolm Date: Fri Dec 10 09:28:48 2021 -0500 jit: set DECL_CONTEXT of RESULT_DECL [PR103562] libgccjit was failing to set the DECL_CONTEXT of function RESULT_DECLs, leading to them failing to be properly handled by the inlining machinery. Fixed thusly. gcc/jit/ChangeLog: PR jit/103562 * jit-playback.c (gcc::jit::playback::context::new_function): Set DECL_CONTEXT of the result_decl. gcc/testsuite/ChangeLog: PR jit/103562 * jit.dg/all-non-failing-tests.h: Add comment about... * jit.dg/test-pr103562.c: New test. Signed-off-by: David Malcolm Diff: --- gcc/jit/jit-playback.c | 1 + gcc/testsuite/jit.dg/all-non-failing-tests.h | 3 ++ gcc/testsuite/jit.dg/test-pr103562.c | 62 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index b412eae6aa8..783a037b11d 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -473,6 +473,7 @@ new_function (location *loc, DECL_ARTIFICIAL (resdecl) = 1; DECL_IGNORED_P (resdecl) = 1; DECL_RESULT (fndecl) = resdecl; + DECL_CONTEXT (resdecl) = fndecl; if (builtin_id) { diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h index a7fddf96db8..3663f726a99 100644 --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h @@ -230,6 +230,9 @@ #undef create_code #undef verify_code +/* test-pr103562.c: We don't add this one, since it touches + the optimization level of the context as a whole. */ + /* test-pr66700-observing-write-through-ptr.c */ #define create_code create_code_pr66700_observing_write_through_ptr #define verify_code verify_code_pr66700_observing_write_through_ptr diff --git a/gcc/testsuite/jit.dg/test-pr103562.c b/gcc/testsuite/jit.dg/test-pr103562.c new file mode 100644 index 00000000000..de361b96bd1 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-pr103562.c @@ -0,0 +1,62 @@ +#include +#include "harness.h" + +struct my_struct { long a; long b; long c; }; + +void create_code (gcc_jit_context *ctxt, void *user_data) +{ + /* Create the equivalent of: + struct my_struct { long a; long b; long c; }; + static struct my_struct deref(struct my_struct *ptr) { return *ptr; } + long get_a(struct my_struct *s) { return deref(s).a; } + and compile it at -O1. */ + gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 1); + + gcc_jit_type *long_type = gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_LONG); + gcc_jit_field* fields[3] = { + gcc_jit_context_new_field(ctxt, NULL, long_type, "a"), + gcc_jit_context_new_field(ctxt, NULL, long_type, "b"), + gcc_jit_context_new_field(ctxt, NULL, long_type, "c"), + }; + gcc_jit_struct *my_struct = + gcc_jit_context_new_struct_type(ctxt, NULL, "my_struct", 3, fields); + gcc_jit_type *my_struct_type = gcc_jit_struct_as_type(my_struct); + gcc_jit_type *my_struct_ptr_type = gcc_jit_type_get_pointer(my_struct_type); + + /* struct my_struct deref(struct my_struct *ptr) { return *ptr; } */ + gcc_jit_param *param_deref = + gcc_jit_context_new_param(ctxt, NULL, my_struct_ptr_type, "ptr"); + gcc_jit_function *func_deref = gcc_jit_context_new_function( + ctxt, NULL, GCC_JIT_FUNCTION_INTERNAL, + my_struct_type, "deref", + 1, ¶m_deref, + 0); + gcc_jit_block *blockDeref = gcc_jit_function_new_block(func_deref, NULL); + gcc_jit_block_end_with_return( + blockDeref, NULL, + gcc_jit_lvalue_as_rvalue(gcc_jit_rvalue_dereference(gcc_jit_param_as_rvalue(param_deref), NULL))); + + /* long get_a(struct my_struct *s) { return deref(s).a; } */ + gcc_jit_param *param_get_a = gcc_jit_context_new_param(ctxt, NULL, my_struct_ptr_type, "s"); + gcc_jit_function *func_get_a = gcc_jit_context_new_function( + ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED, + long_type, "get_a", + 1, ¶m_get_a, + 0); + gcc_jit_block *block_get_a = gcc_jit_function_new_block(func_get_a, NULL); + gcc_jit_rvalue *argsForDeref[1] = {gcc_jit_param_as_rvalue(param_get_a)}; + gcc_jit_rvalue *callDeref = gcc_jit_context_new_call(ctxt, NULL, func_deref, 1, argsForDeref); + gcc_jit_block_end_with_return( + block_get_a, NULL, + gcc_jit_rvalue_access_field(callDeref, NULL, fields[0])); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef long(*fn_type) (struct my_struct*); + fn_type get_a = (fn_type) gcc_jit_result_get_code(result, "get_a"); + + struct my_struct s = {1, 2, 3}; + CHECK_VALUE (get_a(&s), 1); +}