From patchwork Thu Feb 15 22:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoni Boucher X-Patchwork-Id: 201775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp150919dyb; Thu, 15 Feb 2024 14:09:39 -0800 (PST) X-Forwarded-Encrypted: i=4; AJvYcCXWWIePjzMhi/r7pkM2Bp8TBasNIEHsuCF/Kb9i3HWKOWLo3TNY20FopJcXpyCYbBcZipJ24idbJcAe0dsC6/RZUMgVJQ== X-Google-Smtp-Source: AGHT+IFJ6ecPuUjcAuZsrWlAZopkvcmhfYgLVnasLN6NC//Vp/UXXwIWCCPxWXNbazJhcSxAQU/G X-Received: by 2002:a05:620a:1462:b0:787:290c:7f18 with SMTP id j2-20020a05620a146200b00787290c7f18mr3537151qkl.56.1708034979474; Thu, 15 Feb 2024 14:09:39 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1708034979; cv=pass; d=google.com; s=arc-20160816; b=QP9EZq2Wdmlrswt2J6tdqrkwCs3xb7uP4Bq9sahDZvslUTAFFYfOaYEtuesIj4gvUN yfjZ4qTSIgDju70I832fPdQdo/zA5MH2FIdrXjOXH0zGOycSna3GZQt8thW3CJxKAxWz ekFhdepkr6z6aAY5Y3HATvf8ZTTe9ucRuJwN+Y/NMLcFw3zlmBCxq7Gu5xvJck25Crq+ JyDoIjn8uvhS9KB5zgCzvmaZwvdYOBr5QAGVVP5KLb7E0GFImvXBJRAGpZlD/Q82JzeF zb1/IIhshXbZK/3BdXVDiIFp6mjpi3Nl6P2jP5EnRZsFvDUhzIlwEdcqZWX0ZJH2oiak k8Bw== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id:mime-version :user-agent:autocrypt:date:cc:to:from:subject:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=er2FQFMKD3JyvceBF2M740tX+F4/m+Y6gXqq+M6ieEY=; fh=vAsBZubqglMVgYvXuALnbO1gpFxpxAkhTRAP1jtVR04=; b=AIVUiLfDA8rMuNQqyLBQo3Ht9TwNITLXGfDgHncAJGfWVGNhPAgj3IQz/yX3vyp9SC 3dSHRTAYPRRDDeu+1/Cx6tiWbfUx8YPM1/DsO1WmiSy0WLuj/CV8PnNHtSOVVhUYj/EC pOfqKHf4MSR0sZyZTWyjc9bJK76a+HdS1BrJ6TOzAKJF0uHjvCHuuzHlXJ+589XrIvg0 5KcWcdIGzb7rlqYFGQXghrhWv+EbUlMv9X/3J/jp7bvhbXgeEtkLBeznCjijnEDHTUAY hvc2YNjTrUmv6l8qxbwT2o0mNiysHV83ZlG6MZNLMMc18UQvN/qjiebBXxUE1bGdTsYb V/2g==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2022 header.b=RGFiBvfB; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j14-20020a05620a0a4e00b00785db64168fsi2436508qka.554.2024.02.15.14.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 14:09:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2022 header.b=RGFiBvfB; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E27D386D636 for ; Thu, 15 Feb 2024 22:09:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from sender4-pp-o90.zoho.com (sender4-pp-o90.zoho.com [136.143.188.90]) by sourceware.org (Postfix) with ESMTPS id 873F3386D604; Thu, 15 Feb 2024 22:08:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 873F3386D604 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 873F3386D604 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=136.143.188.90 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708034933; cv=pass; b=WQInLFX5zDIXt+PWLmehbk+QOG17Hb21BmF2siAJMrc1NhX0+QtIHjrhxy1zPot0ZM9YT5nqWE/PApJ4slCxuzjG6LMDE9u733+2Bf2ceozecBk9EJ45Gc3G1VKFGQz0/irOgXeax0U9dKOPcoLce/9sEabeHRhqlCB5g+vFKo0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708034933; c=relaxed/simple; bh=zVUfT+UJ7Bpq5LuYqn1pXY2F3qYSxZm7wWoqv3hH8iY=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=pYtwiq+1yE4AzC4x767qFICK9C49QDZftX7e4hKt7Ld6+1l2qUMfAg4esjj0O56gpqwWz8dCfRSgdgbivtWodvuXnxAvZp0Kect4/jm/Y4pg2cETQ+XLGELp5dvpvmYNGjgi4VWMpcBgC1XCIKuJKmK5OlzV/z/UTB2xoqX6B3o= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1708034926; cv=none; d=zohomail.com; s=zohoarc; b=N6COHkfXlQ0M0/ZV5oqBvnKwyx0xbZMmOWtSHjhnjaTAoIESozX+/Vgw72RXYpTv+ew2PHcHVvK4mv2QNuvX8bUOGb/DoJCbpyxdwitTejhpb+NeWCzKzQb/OFi31Vg9SjH7BVBJTLRIwVJBB5QhLdFGrOXbNd9YgbSM1DQVLTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708034926; h=Content-Type:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=er2FQFMKD3JyvceBF2M740tX+F4/m+Y6gXqq+M6ieEY=; b=Trds0GwFiktf1U0xkaqOmKP075AyE0DNLzEmsh9AZgrzN6vT5kvTpp3LfeQYTeWVV9JECCcH3EkfqnN2R5eFisyTRRZtMbaiRPaGYqPRJ9vpdACB/s9gIRKT9PIwt51MNqa1GTk6g9GpGC2G1tmQ+C3RBMg33z3MkhIyVDdm4Wo= 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=1708034926; 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=er2FQFMKD3JyvceBF2M740tX+F4/m+Y6gXqq+M6ieEY=; b=RGFiBvfBwDJlBNKPc5HASkY8c2FBWyq1Yt2ud0tKum7WYllCTbY9feAGlt/MirZr jXWvQs3hyEjdC2P8jj1CplbJkXgycssk90knknVBdqgD5z8hwW70TJjt1j8kNvIgSNF ZgTndlVOQ4fePjcPdrOcm8k/E9+VSQ/whBObp8qQ= Received: from [192.168.1.172] (38.87.11.6 [38.87.11.6]) by mx.zohomail.com with SMTPS id 1708034924998324.19913200994415; Thu, 15 Feb 2024 14:08:44 -0800 (PST) Message-ID: <63ab69e027ce69d97dd361561675d3c323983b92.camel@zoho.com> Subject: [PATCH] libgccjit: Add option to allow special characters in function names From: Antoni Boucher To: "gcc-patches@gcc.gnu.org" , "jit@gcc.gnu.org" Cc: David Malcolm Date: Thu, 15 Feb 2024 17:08:42 -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.3 MIME-Version: 1.0 X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-1.1.0/208.5.86 Feedback-ID: rr08011228dcad5b57af9392df5bc0097a0000dd53375b668ae2b00853ffa0ed286f2a289cf5100ecd5a477a20:zu080112264dadec994d14cf6a351b8b7f0000360bf721066a6dae603fb1e33cb386dcb49e73fa332472d6:rf08011232c77075f4d79e8f7964293f2f0000ad5611c0adc98822e97d94dabde064482df18d42b9017ad4db055bb224505f4958367be7:ZohoMail X-ZohoMailClient: External X-Spam-Status: No, score=-11.5 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, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791004486718009351 X-GMAIL-MSGID: 1791004486718009351 Hi. This patch adds a new option to allow special characters like . and $ in function names. This is useful to allow for mangling using those characters. Thanks for the review. From 89a92e561ca83a622dcc22a6500ca2b17551edb1 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 15 Feb 2024 17:03:22 -0500 Subject: [PATCH] libgccjit: Add option to allow special characters in function names gcc/jit/ChangeLog: * docs/topics/contexts.rst: Add documentation for new option. * jit-recording.cc (recording::context::get_bool_option): New method. * jit-recording.h (get_bool_option): New method. * libgccjit.cc (gcc_jit_context_new_function): Allow special characters in function names. * libgccjit.h (enum gcc_jit_bool_option): New option. gcc/testsuite/ChangeLog: * jit.dg/test-special-chars.c: New test. --- gcc/jit/docs/topics/contexts.rst | 4 +++ gcc/jit/jit-recording.cc | 15 ++++++++- gcc/jit/jit-recording.h | 3 ++ gcc/jit/libgccjit.cc | 8 +++-- gcc/jit/libgccjit.h | 3 ++ gcc/testsuite/jit.dg/test-special-chars.c | 41 +++++++++++++++++++++++ 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/jit.dg/test-special-chars.c diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst index 10a0e50f9f6..4af75ea7418 100644 --- a/gcc/jit/docs/topics/contexts.rst +++ b/gcc/jit/docs/topics/contexts.rst @@ -453,6 +453,10 @@ Boolean options If true, the :type:`gcc_jit_context` will not clean up intermediate files written to the filesystem, and will display their location on stderr. + .. macro:: GCC_JIT_BOOL_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES + + If true, allow special characters like . and $ in function names. + .. function:: void \ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, \ int bool_value) diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 83a8b299b91..962c37ee87e 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -1511,6 +1511,18 @@ recording::context::set_bool_option (enum gcc_jit_bool_option opt, log_bool_option (opt); } +int +recording::context::get_bool_option (enum gcc_jit_bool_option opt) +{ + if (opt < 0 || opt >= GCC_JIT_NUM_BOOL_OPTIONS) + { + add_error (NULL, + "unrecognized (enum gcc_jit_bool_option) value: %i", opt); + return 0; + } + return m_bool_options[opt]; +} + void recording::context::set_inner_bool_option (enum inner_bool_option inner_opt, int value) @@ -1863,7 +1875,8 @@ static const char * const "GCC_JIT_BOOL_OPTION_DUMP_SUMMARY", "GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING", "GCC_JIT_BOOL_OPTION_SELFCHECK_GC", - "GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES" + "GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES", + "GCC_JIT_BOOL_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES", }; static const char * const diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 4833b2d3f52..377b60c662c 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -267,6 +267,9 @@ public: set_bool_option (enum gcc_jit_bool_option opt, int value); + int + get_bool_option (enum gcc_jit_bool_option opt); + void set_inner_bool_option (enum inner_bool_option inner_opt, int value); diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 5a1308b2b8c..3c5ff5a2a59 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -1222,10 +1222,13 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt, Eventually we'll need some way to interact with e.g. C++ name mangling. */ { + int special_chars_allowed + = ctxt->get_bool_option (GCC_JIT_BOOL_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES); /* Leading char: */ char ch = *name; RETURN_NULL_IF_FAIL_PRINTF2 ( - ISALPHA (ch) || ch == '_', + ISALPHA (ch) || ch == '_' || (special_chars_allowed + && (ch == '.' || ch == '$')), ctxt, loc, "name \"%s\" contains invalid character: '%c'", name, ch); @@ -1233,7 +1236,8 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt, for (const char *ptr = name + 1; (ch = *ptr); ptr++) { RETURN_NULL_IF_FAIL_PRINTF2 ( - ISALNUM (ch) || ch == '_', + ISALNUM (ch) || ch == '_' || (special_chars_allowed + && (ch == '.' || ch == '$')), ctxt, loc, "name \"%s\" contains invalid character: '%c'", name, ch); diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index d45b767c262..694f45f34e5 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -244,6 +244,9 @@ enum gcc_jit_bool_option their location on stderr. */ GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, + /* If true, allow special characters like . and $ in function names. */ + GCC_JIT_BOOL_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES, + GCC_JIT_NUM_BOOL_OPTIONS }; diff --git a/gcc/testsuite/jit.dg/test-special-chars.c b/gcc/testsuite/jit.dg/test-special-chars.c new file mode 100644 index 00000000000..1bca71164d8 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-special-chars.c @@ -0,0 +1,41 @@ +#include +#include + +#include "libgccjit.h" + +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + gcc_jit_context_set_bool_option (ctxt, + GCC_JIT_BOOL_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES, 1); + + /* Let's try to inject the equivalent of: + void + name$with.special_chars (void) + { + } + */ + gcc_jit_type *void_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); + + /* Build the test_fn. */ + gcc_jit_function *test_fn = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + void_type, + "name$with.special_chars", + 0, NULL, + 0); + + gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL); + gcc_jit_block_end_with_void_return ( + block, NULL); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_NON_NULL (result); +} -- 2.43.0