From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id ED581385801D for ; Fri, 10 Dec 2021 22:54:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED581385801D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-59-IkCIJZdvO6KXF39NOyo6Tg-1; Fri, 10 Dec 2021 17:54:49 -0500 X-MC-Unique: IkCIJZdvO6KXF39NOyo6Tg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C84881CCB4; Fri, 10 Dec 2021 22:54:48 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.16.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66F411B42C; Fri, 10 Dec 2021 22:54:46 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Subject: [committed] jit: set DECL_CONTEXT of RESULT_DECL [PR103562] Date: Fri, 10 Dec 2021 17:54:41 -0500 Message-Id: <20211210225441.3889005-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2021 22:54:54 -0000 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. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r12-5903-ga2f4b4b76cdd0a4150e82e69fae4a70c54b523d2. 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 --- 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(+) create mode 100644 gcc/testsuite/jit.dg/test-pr103562.c diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index b9c05864900..a9f52cbd0ef 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); +} -- 2.26.3