From patchwork Fri Nov 17 22:48:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoni Boucher X-Patchwork-Id: 80192 X-Patchwork-Delegate: dmalcolm@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B88C73858438 for ; Fri, 17 Nov 2023 22:49:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from sender3-pp-o99.zoho.com (sender3-pp-o99.zoho.com [136.143.184.99]) by sourceware.org (Postfix) with ESMTPS id BFCAE3858D20; Fri, 17 Nov 2023 22:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFCAE3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=zoho.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zoho.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BFCAE3858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=136.143.184.99 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700261338; cv=pass; b=gzPD6MTphSdDHBTxOxToSAf9qeUC6Qv92JHDPwzPyEsfPZp9pRmPp74Sa3leVoruaRwJAkXAjKoZQYCV+75rtWjQ7830mBJJ1+BCU6FXoV9gFx9gv/xeZ9loKUZTdPO9eILXVJUGCtDFLTYTIFrH/E5DBhTwxiGHm2GytXXkgMA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700261338; c=relaxed/simple; bh=5M1PiJ6PMNzFKZPgyO3AlflhD4jcL+ZdDhonS58hhR0=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=NLwfgmkrV94fVa7SqZpgIDhGEQnQ3HK4k4Ha+GxlZy0J3IWA0qWNUTCsfP7Qq1g7ItuG7uWe+scRAs4VX4FITvnn0pqAhO9UXx5CPYHrSSXEMlcFV3ObDN652OARN7I9NDiqCHKMwauKcmtu2PYnJR18OWVLX2x5iUnnWCGEji8= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1700261330; cv=none; d=zohomail.com; s=zohoarc; b=RtpIDXO68CH98TEvPHl5xkTbjrqEKKIP+99PQjUdTMjXGzW112soObDjDju4sEOJJoVRjaa5viG6c8Xla8uhzMKo4aiAvAUb94zlKwN/9dVUom6ySU1jfn8lAQKGTdnML44Y4gcbGDcB782c6NpSszx94Q+CKhnOzPMO4nn4usU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700261330; h=Content-Type:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=G0IAQOEA7mNsrhOv9oTCz1p8GMSVy9VqI6a9Wdnbyck=; b=SDoeVdFq/6Bjb2LqAuDJKDr0L+HOyRDCqSsLzHdXOZnQPzetdY+uQWP56LQS1z14vFXfIDj+52ucbaMb4fLEKyqGhX7f8vOp25omMYeHv+AXjokTPC4nlXOffTi862KgfyN7i29LbnSEJwdRIWW3qWJQEnnQxcuBIsNR8em5tM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zoho.com; spf=pass smtp.mailfrom=bouanto@zoho.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1700261330; s=zm2022; d=zoho.com; i=bouanto@zoho.com; h=Message-ID:Subject:Subject:From:From:To:To:Cc:Cc:Date:Date:Content-Type:MIME-Version:Feedback-ID:Message-Id:Reply-To; bh=G0IAQOEA7mNsrhOv9oTCz1p8GMSVy9VqI6a9Wdnbyck=; b=AMVvY64lUyKBD12ZUE+gucZpCZ6GgPItsJCyyZhUx9WcbDyRQm1H0RYB4VzTFDZT xjYCMu4FFPGQ10Wm0BAveeGE4xE5g/wTUyn8ax5FWoM0WO+N4Su26vZd89XjSRCyl9d OHB4qdr0KYW8qFUpx0oqXZYF9PYzn65h7725UmvM= Received: from [192.168.1.172] (38.87.11.6 [38.87.11.6]) by mx.zohomail.com with SMTPS id 170026132873673.55873616394308; Fri, 17 Nov 2023 14:48:48 -0800 (PST) Message-ID: <4568a2ea1baa146f2f4b83636d8329c6dd351599.camel@zoho.com> Subject: [PATCH] libgccjit: Add ways to set the personality function From: Antoni Boucher To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Date: Fri, 17 Nov 2023 17:48:47 -0500 Autocrypt: addr=bouanto@zoho.com; prefer-encrypt=mutual; keydata=mQENBFOSMLQBCADO5aw6Ys8thMQUNzrwAnfJX2wbgWiz0pQ01DjYj22eeIpChkoZn6LWdt4dieq30u2rFi/yQzJ02foHwI2+aL9rU6xz/x4TwqyRJQGMOqklNc3R+pdXmH4WDQkQDWmLxvc07vu+zb8Tx5A6pMDh4J2ncCEhLEUcH39Yq/yg4eBnFwUX6N7kakvHrnScGNqhnSFCacoJeMJUAR+1G7VBSBd++jmnHLnx3mj7QkRZVECJUw2zqiv1yReCC6GU4SvqLjdqm5ZGeoWOqD/NHjBRoEeOVjzp6M/qOjjWRbkJVqmvgfcD8UytSSqqboR35YFT4L+rZt2ri3T12MJb3i5syCAXABEBAAG0IUFudG9uaSBCb3VjaGVyIDxib3VhbnRvQHpvaG8uY29tPokBVgQTAQgAQAIbIwcLCQgHAwIBBhUIAgkKCwQWAgMBAh4BAheAFiEEOELC4Uw1Jeb66YE6RVeGAwR4zcEFAlz4QM4FCRLMEZoACgkQRVeGAwR4zcFBQQf/afttJrA/puADQZhrDfkgr0MFvq6iB+GCy1b8BkXimk1TOXTPt87YLehSeijNu3JkYhl5eRc87BNfU9J87KfI/KIy6hZxqlDXk16FhW9bw/7wYEA0hpb3MUn7xLElXDT0ZHaD+KTe8Oun7qfzgx5RlL6r/WODf3CkSpO085R/rfeBqDEx9mVlhDWgq6Az3CZoD+3CqiCKVqmDuHTWz4kwrd9AM5eVcLvvLKnZIdoIp+G5Ao6BvaGlZyfenN1iOSjLy2NXNt4MnUt0lUYEP5KSIIRhHQ8xkUbj7eWUmaahkxhNb3fH3sAPwGnRZrPpb4rgYzNmSk63wWMh9M2xk+rLb7kBDQRTkjC0AQgAumZzsAV/UFWI+dpzebQfma36kKYZZFuseant5sq/HWP553XQ/U6ttJiKyN5MpCqtxvCAoRplf42YhlHuFqgf73WJxoJ6Y+sdyqoBSwlR+ gzAneAmsa8gmmY0wawH0Z2leazjKuS7mJjVEQZg0ZGsiCVRGeRnDqFGzDEzDc9ngWKSoTq0fKzlGy1X85OrtmUrvEbhSo6HP+FoeunHkIqrxu3w3vDoFEXxVQlKI6V3I4nCz5n6DB8WR3L7nsiiTnOiGirPw1ngvWFLW86kkA4FJpayc8Xl3va3SLY+2y4yuROboX2DVI4AC/Qeug/mDiBicPxkP6YfUartQRMe6obkEQARAQABiQE8BBgBCAAmAhsMFiEEOELC4Uw1Jeb66YE6RVeGAwR4zcEFAlz4QRsFCRLMEecACgkQRVeGAwR4zcE56ggAgTgrJInBKC+7552Dpccuo6Clh3wZfjlNLv9/6r5lKEbaNzaTrfhPiAP4WgnluIUmj8amOFLFJpj+BAVNOXpZ4D2R3o9ch8z7fot+fW4Yw+PKIxH4I2xEys8ndoEB3aiQwHjKcGIhkIU7uyMJFQr2aWjdTY0gmXw0YZueHOSLgo7uX4XKxB8fEO/yto/Tff2YBAAq+AtNwt+Gh5YS9rZw7rwUTWMi84yVOlc+zRE79E9NJkvdTwX7IJYo64VzIRNfgHsn7QNdVzuM1XIFHl+Glk6cIlI8s6BO7nEoCn3hTF104fQTAO3fEs+XXZOKXo2lk8faowEoPq5r58StrV0nyg== User-Agent: Evolution 3.50.1 MIME-Version: 1.0 X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-1.1.0/200.232.44 Feedback-ID: rr08011228e758b768f9a0e0df002e1eb30000db6590e79050c0ff2916d8790d6c5de0c09377a0a4e68d5a6393:zu080112268846aa5b82d3f3170517a083000080e1ec5ea30ca02348a7f6b2365e905a5b12b4e99d9beff1:rf080112324f75f62376e49249a3ece5e900007c136a64df924f77b11eeea9ba575b29c04351cea3ebd5322eebfc2e961b34829faa9cba:ZohoMail X-ZohoMailClient: External X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi. This adds functions to set the personality function (bug 112603). I'm not sure I can make a test for this: it seems the personality function will not be set if there are no try/catch inside the functions. Do you know a way to keep the personality function that is set in this case? Or should we wait until I send the patch for try/catch? Thanks for the review. From 6beb6452c7bac9ecbdaea750d61d6e6c6bd3ed8f Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 16 Apr 2023 13:19:20 -0400 Subject: [PATCH] libgccjit: Add ways to set the personality function gcc/ChangeLog: PR jit/112603 * expr.cc (build_personality_function_with_name): New function. * tree.cc (tree_cc_finalize): Cleanup gcc_eh_personality_decl. * tree.h (build_personality_function_with_name): New decl. gcc/jit/ChangeLog: PR jit/112603 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_26): New ABI tag. * docs/topics/functions.rst: Document the functions gcc_jit_set_global_personality_function_name and gcc_jit_function_set_personality_function. * dummy-frontend.cc (jit_gc_root): New variable. (jit_preserve_from_gc): New function. (jit_langhook_init): Initialize new variables. (jit_langhook_eh_personality): New hook. (LANG_HOOKS_EH_PERSONALITY): New hook. * jit-playback.cc (set_personality_function): New function. * jit-playback.h: New decl. * jit-recording.cc (memento_of_set_personality_function::make_debug_string, recording::memento_of_set_personality_function::write_reproducer, recording::function::set_personality_function, recording::memento_of_set_personality_function::replay_into): New functions * jit-recording.h (class memento_of_set_personality_function): New class. (recording::function::set_personality_function): New function. * libgccjit.cc (gcc_jit_function_set_personality_function, gcc_jit_set_global_personality_function_name): New functions. * libgccjit.h (gcc_jit_set_global_personality_function_name, gcc_jit_function_set_personality_function): New functions. * libgccjit.map: New functions. gcc/testsuite/ChangeLog: * jit.dg/test-personality-function.c: New test. * jit.dg/all-non-failing-tests.h: Mention test-personality-function.c. --- gcc/expr.cc | 8 +++ gcc/jit/docs/topics/compatibility.rst | 10 ++++ gcc/jit/docs/topics/functions.rst | 28 ++++++++++ gcc/jit/dummy-frontend.cc | 36 ++++++++++++ gcc/jit/jit-playback.cc | 8 +++ gcc/jit/jit-playback.h | 3 + gcc/jit/jit-recording.cc | 44 +++++++++++++++ gcc/jit/jit-recording.h | 23 ++++++++ gcc/jit/libgccjit.cc | 22 ++++++++ gcc/jit/libgccjit.h | 8 +++ gcc/jit/libgccjit.map | 6 ++ gcc/testsuite/jit.dg/all-non-failing-tests.h | 3 + .../jit.dg/test-personality-function.c | 55 +++++++++++++++++++ gcc/tree.cc | 1 + gcc/tree.h | 1 + 15 files changed, 256 insertions(+) create mode 100644 gcc/testsuite/jit.dg/test-personality-function.c diff --git a/gcc/expr.cc b/gcc/expr.cc index 556bcf7ef59..25d50289b24 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -13559,6 +13559,14 @@ build_personality_function (const char *lang) name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL)); + return build_personality_function_with_name (name); +} + +tree +build_personality_function_with_name (const char *name) +{ + tree decl, type; + type = build_function_type_list (unsigned_type_node, integer_type_node, integer_type_node, long_long_unsigned_type_node, diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index ebede440ee4..31c3ef6401a 100644 --- a/gcc/jit/docs/topics/compatibility.rst +++ b/gcc/jit/docs/topics/compatibility.rst @@ -378,3 +378,13 @@ alignment of a variable: -------------------- ``LIBGCCJIT_ABI_25`` covers the addition of :func:`gcc_jit_type_get_restrict` + +.. _LIBGCCJIT_ABI_26: + +``LIBGCCJIT_ABI_26`` +-------------------- +``LIBGCCJIT_ABI_26`` covers the addition of functions to set the personality +function: + + * :func:`gcc_jit_function_set_personality_function` + * :func:`gcc_jit_set_global_personality_function_name` diff --git a/gcc/jit/docs/topics/functions.rst b/gcc/jit/docs/topics/functions.rst index cf5cb716daf..e59885c3549 100644 --- a/gcc/jit/docs/topics/functions.rst +++ b/gcc/jit/docs/topics/functions.rst @@ -197,6 +197,34 @@ Functions .. type:: gcc_jit_case +.. function:: void + gcc_jit_function_set_personality_function (gcc_jit_function *fn, + gcc_jit_function *personality_func) + + Set the personality function of ``fn`` to ``personality_func``. + + were added in :ref:`LIBGCCJIT_ABI_26`; you can test for their presence + using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_PERSONALITY_FUNCTION + +.. function:: void + gcc_jit_set_global_personality_function_name (char* name) + + Set the global personality function. + + This is mainly useful to prevent the optimizer from unsetting the personality + function set on other functions. + + were added in :ref:`LIBGCCJIT_ABI_26`; you can test for their presence + using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_PERSONALITY_FUNCTION + Blocks ------ .. type:: gcc_jit_block diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc index a729086bafb..c9dedd59b24 100644 --- a/gcc/jit/dummy-frontend.cc +++ b/gcc/jit/dummy-frontend.cc @@ -146,6 +146,20 @@ const struct attribute_spec jit_format_attribute_table[] = { NULL, 0, 0, false, false, false, false, NULL, NULL } }; +char* jit_personality_func_name = NULL; +static tree personality_decl; + +/* FIXME: This is a hack to preserve trees that we create from the + garbage collector. */ + +static GTY (()) tree jit_gc_root; + +void +jit_preserve_from_gc (tree t) +{ + jit_gc_root = tree_cons (NULL_TREE, t, jit_gc_root); +} + /* Attribute handlers. */ /* Handle a "noreturn" attribute; arguments as in @@ -578,6 +592,8 @@ jit_end_diagnostic (diagnostic_context *context, static bool jit_langhook_init (void) { + jit_gc_root = NULL_TREE; + personality_decl = NULL_TREE; gcc_assert (gcc::jit::active_playback_ctxt); JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); @@ -694,6 +710,26 @@ jit_langhook_getdecls (void) return NULL; } +static tree +jit_langhook_eh_personality (void) +{ + if (personality_decl == NULL_TREE) + { + if (jit_personality_func_name != NULL) + { + personality_decl = + build_personality_function_with_name (jit_personality_func_name); + jit_preserve_from_gc (personality_decl); + } + else + return lhd_gcc_personality (); + } + return personality_decl; +} + +#undef LANG_HOOKS_EH_PERSONALITY +#define LANG_HOOKS_EH_PERSONALITY jit_langhook_eh_personality + #undef LANG_HOOKS_NAME #define LANG_HOOKS_NAME "libgccjit" diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc index 18cc4da25b8..ef3152a3aed 100644 --- a/gcc/jit/jit-playback.cc +++ b/gcc/jit/jit-playback.cc @@ -1857,6 +1857,14 @@ playback::function::get_address (location *loc) return new rvalue (m_ctxt, t_fnptr); } +void +playback::function:: +set_personality_function (function *personality_function) +{ + DECL_FUNCTION_PERSONALITY (m_inner_fndecl) = + personality_function->as_fndecl (); +} + /* Build a statement list for the function as a whole out of the lists of statements for the individual blocks, building labels for each block. */ diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index f9e29d0baec..2ff576a576f 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -508,6 +508,9 @@ public: rvalue * get_address (location *loc); + void + set_personality_function (function *personality_function); + void build_stmt_list (); diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 9b5b8005ebe..bb18aaf44b3 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -4164,6 +4164,50 @@ recording::function::replay_into (replayer *r) m_builtin_id)); } +/* Implementation of recording::memento::make_debug_string for + setting a personality function. */ + +recording::string * +recording::memento_of_set_personality_function::make_debug_string () +{ + return string::from_printf (m_ctxt, + "%s", + m_personality_function->get_debug_string ()); +} + +/* Implementation of recording::memento::write_reproducer for setting the + personality function. */ + +void +recording::memento_of_set_personality_function::write_reproducer (reproducer &r) +{ + r.write (" gcc_jit_function_set_personality_function (%s,\n" + " %s);\n", + r.get_identifier (m_function), + r.get_identifier (m_personality_function)); +} + +void +recording::function::set_personality_function (function *function) +{ + recording::memento_of_set_personality_function *result = + new memento_of_set_personality_function (m_ctxt, this, function); + m_ctxt->record (result); +} + +/* The implementation of class + gcc::jit::recording::memento_of_set_personality_function. */ + +/* Implementation of pure virtual hook recording::memento::replay_into + for recording::memento_of_set_personality_function. */ + +void +recording::memento_of_set_personality_function::replay_into (replayer *) +{ + m_function->playback_function ()->set_personality_function ( + m_personality_function->playback_function ()); +} + /* Create a recording::local instance and add it to the functions's context's list of mementos, and to the function's list of locals. diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 4a8082991fb..0ccb0f38bb9 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -1342,6 +1342,8 @@ public: rvalue *get_address (location *loc); + void set_personality_function (function *function); + private: string * make_debug_string () final override; void write_reproducer (reproducer &r) final override; @@ -1359,6 +1361,27 @@ private: type *m_fn_ptr_type; }; +class memento_of_set_personality_function : public memento +{ +public: + memento_of_set_personality_function (context *ctx, + function *func, + function *personality_function) + : memento (ctx), + m_function (func), + m_personality_function (personality_function) {} + + void replay_into (replayer *r) final override; + +private: + string * make_debug_string () final override; + void write_reproducer (reproducer &r) final override; + +private: + function *m_function; + function *m_personality_function; +}; + class block : public memento { public: diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 0451b4df7f9..67d9036249e 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -3590,6 +3590,28 @@ gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt, ctxt->add_command_line_option (optname); } +/* Public entrypoint. See description in libgccjit.h. + After error-checking, the real work is done by the + gcc::jit::recording::function::set_personality_function method, in + jit-recording.c. */ + +void +gcc_jit_function_set_personality_function (gcc_jit_function *fn, + gcc_jit_function *personality_func) +{ + RETURN_IF_FAIL (fn, NULL, NULL, "NULL function"); + + fn->set_personality_function (personality_func); +} + +extern char* jit_personality_func_name; + +void +gcc_jit_set_global_personality_function_name (char* name) +{ + jit_personality_func_name = name; +} + /* Public entrypoint. See description in libgccjit.h. The real work is done by the diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 749f6c24177..867480b0331 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -1797,6 +1797,14 @@ extern gcc_jit_rvalue * gcc_jit_function_get_address (gcc_jit_function *fn, gcc_jit_location *loc); +#define LIBGCCJIT_HAVE_PERSONALITY_FUNCTION + +extern void +gcc_jit_set_global_personality_function_name (char* name); + +void +gcc_jit_function_set_personality_function (gcc_jit_function *fn, + gcc_jit_function *personality_func); #define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index 8b90a0e2ff3..2a0eb819a52 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -276,3 +276,9 @@ LIBGCCJIT_ABI_25 { global: gcc_jit_type_get_restrict; } LIBGCCJIT_ABI_24; + +LIBGCCJIT_ABI_26 { + global: + gcc_jit_set_global_personality_function_name; + gcc_jit_function_set_personality_function; +} LIBGCCJIT_ABI_25; diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h index e762563f9bd..3785a788ffa 100644 --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h @@ -322,6 +322,9 @@ /* test-setting-alignment.c: This can't be in the testcases array as it is target-specific. */ +/* test-personality-function.c: This can't be in the testcases array as it + is target-specific. */ + /* test-string-literal.c */ #define create_code create_code_string_literal #define verify_code verify_code_string_literal diff --git a/gcc/testsuite/jit.dg/test-personality-function.c b/gcc/testsuite/jit.dg/test-personality-function.c new file mode 100644 index 00000000000..1125636e362 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-personality-function.c @@ -0,0 +1,55 @@ +/* { dg-do compile { target x86_64-*-* } } */ + +#include +#include + +#include "libgccjit.h" + +/* We don't want set_options() in harness.h to set -O3 so our little local + is optimized away. */ +#define TEST_ESCHEWS_SET_OPTIONS +static void set_options (gcc_jit_context *ctxt, const char *argv0) +{ +} + +#define TEST_COMPILING_TO_FILE +#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER +#define OUTPUT_FILENAME "output-of-test-personality-function.c.s" +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + gcc_jit_context_add_driver_option (ctxt, "-fexceptions"); + gcc_jit_context_add_command_line_option (ctxt, "-fexceptions"); + gcc_jit_set_global_personality_function_name ("my_personality_function"); + + gcc_jit_type *void_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); + + gcc_jit_function *personality_func = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + void_type, + "my_personality_function", + 0, NULL, + 0); + gcc_jit_block *block_personality = gcc_jit_function_new_block (personality_func, NULL); + gcc_jit_block_end_with_void_return (block_personality, NULL); + + gcc_jit_function *func_a = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + void_type, + "a", + 0, NULL, + 0); + + + gcc_jit_block *block_a = gcc_jit_function_new_block (func_a, NULL); + gcc_jit_block_end_with_void_return (block_a, NULL); + gcc_jit_function_set_personality_function (func_a, personality_func); +} + +/* { dg-final { jit-verify-output-file-was-created "" } } */ +/* { dg-final { jit-verify-assembler-output ".cfi_personality TODO" } } */ diff --git a/gcc/tree.cc b/gcc/tree.cc index a3d907a4ac0..30ba8d6d9cd 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -15115,6 +15115,7 @@ void tree_cc_finalize (void) { clear_nonstandard_integer_type_cache (); + gcc_eh_personality_decl = NULL; vec_free (bitint_type_cache); } diff --git a/gcc/tree.h b/gcc/tree.h index 086b55f0375..042afe6a101 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -6672,6 +6672,7 @@ extern tree get_inner_reference (tree, poly_int64 *, poly_int64 *, tree *, machine_mode *, int *, int *, int *); extern tree build_personality_function (const char *); +extern tree build_personality_function_with_name (const char *); struct GTY(()) int_n_trees_t { /* These parts are initialized at runtime */ -- 2.42.1