From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6371 invoked by alias); 23 Jan 2020 11:14:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 6353 invoked by uid 89); 23 Jan 2020 11:14:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.3 required=5.0 tests=AWL,BAYES_00,FORGED_SPF_HELO,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=Kindly X-HELO: EUR05-AM6-obe.outbound.protection.outlook.com Received: from mail-am6eur05on2089.outbound.protection.outlook.com (HELO EUR05-AM6-obe.outbound.protection.outlook.com) (40.107.22.89) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 11:14:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okVstU9FSMHVO2GsPIDT54BH6YnpOvKB/SL6vJxeEf0=; b=uqRSC+QWSkE0ja1a6SvgQu1iwltwoe/7UWD/XmHFFFDUyZKJVgm99YVSwdC9ziXiC3BFXzcSx4N3/S07X3Q//0MH6vbEnSQ248Gnp5Xc02qtpG6H24dP1wNbefZT29w5h719H0B2dJ/k2t0OEhsT7elvxfMQOx+BZ4nD8ynepEE= Received: from VI1PR08CA0095.eurprd08.prod.outlook.com (2603:10a6:800:d3::21) by AM6PR08MB3607.eurprd08.prod.outlook.com (2603:10a6:20b:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.22; Thu, 23 Jan 2020 11:14:43 +0000 Received: from AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::200) by VI1PR08CA0095.outlook.office365.com (2603:10a6:800:d3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.20 via Frontend Transport; Thu, 23 Jan 2020 11:14:43 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT048.mail.protection.outlook.com (10.152.17.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Thu, 23 Jan 2020 11:14:43 +0000 Received: ("Tessian outbound 1da651c29646:v40"); Thu, 23 Jan 2020 11:14:43 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 851ef36e9b6783da X-CR-MTA-TID: 64aa7808 Received: from d6ccbb965e47.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4BE911BB-27BC-422B-A1EC-BFC800149511.1; Thu, 23 Jan 2020 11:14:38 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d6ccbb965e47.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 23 Jan 2020 11:14:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IySXOB//rQBbjIl1M2vl6rC8YWZlFRxCJYAtRF907nssr/YXGQPb64GM6whQ4MiOR6I/vOxAa+/I2//HPDF8CPbCHxemNlTM+zzQ/zsEnpDWHh2lXz+TKiUHB4aHUB28VayL65sjI7MedVfpQldPIJB09Z+0PEElfESpxOU7xVZIsQOMkYoleCj4YxWyAIslMQg2aDRlt5wwEnhicLkVKHZkPmnRDbIaNXX0/flnIRDnkMWHhJlsoEwtx15jOuaacAtndtkSNkTJW0ZLEs+1aLTmHjWHRcw4cLy48TQQKow8QzBXLQ3r1mgcWGKEbKZDfaAcEsi3lz970ZT3aM7Ozg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okVstU9FSMHVO2GsPIDT54BH6YnpOvKB/SL6vJxeEf0=; b=W9EHWVJZ2heBzmRsdwwiukWCzdXQ6rDMMYjvxQQGiJqifXomMXez5aK+pG0MSy7YR2lApHZ81x+8piqgbQ1/npDaxiPG+ZwUwUE0plLN3hDWydXflV8kse00sZ7g0ecAVCtAgqWXZBMvUxdi1pvYVVHnXrebXSoVSzudNHsogGyNJyndsd/vouUjorrtKJSpKAI90wWYi4kIiYHp4VXGn7OVEMD8NoBcw9TOa32eQ0cikl5BxbyEfzJ7y79ZjdcqQkxqGKXLK4L7kmbsp3BCavEBegkFKU/4EGuccH1CuHizeyZyrQaSuPYvUSa2HcckWyJ1CwSVSruNBeEQxgrROA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okVstU9FSMHVO2GsPIDT54BH6YnpOvKB/SL6vJxeEf0=; b=uqRSC+QWSkE0ja1a6SvgQu1iwltwoe/7UWD/XmHFFFDUyZKJVgm99YVSwdC9ziXiC3BFXzcSx4N3/S07X3Q//0MH6vbEnSQ248Gnp5Xc02qtpG6H24dP1wNbefZT29w5h719H0B2dJ/k2t0OEhsT7elvxfMQOx+BZ4nD8ynepEE= Received: from VI1PR08MB2765.eurprd08.prod.outlook.com (10.170.236.32) by VI1PR08MB3997.eurprd08.prod.outlook.com (20.178.126.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20; Thu, 23 Jan 2020 11:14:37 +0000 Received: from VI1PR08MB2765.eurprd08.prod.outlook.com ([fe80::eca9:5f98:627d:571b]) by VI1PR08MB2765.eurprd08.prod.outlook.com ([fe80::eca9:5f98:627d:571b%6]) with mapi id 15.20.2644.028; Thu, 23 Jan 2020 11:14:37 +0000 Received: from e112547 (217.140.106.49) by LO2P265CA0088.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.11 via Frontend Transport; Thu, 23 Jan 2020 11:14:36 +0000 From: Andrea Corallo To: David Malcolm , "jit@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" , nd Subject: Re: [PATCH][gcc] libgccjit: handle long literals in playback::context::new_string_literal Date: Thu, 23 Jan 2020 11:43:00 -0000 Message-ID: References: <1579772431.117590.ezmlm@gcc.gnu.org> In-Reply-To: <1579772431.117590.ezmlm@gcc.gnu.org> (jit-help@gcc.gnu.org's message of "23 Jan 2020 09:40:31 -0000") Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Andrea.Corallo@arm.com; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6790;OLM:6790; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(396003)(39860400002)(136003)(346002)(366004)(376002)(199004)(189003)(478600001)(66556008)(6636002)(956004)(316002)(66476007)(66446008)(2616005)(6486002)(110136005)(52116002)(64756008)(86362001)(6496006)(81156014)(81166006)(71200400001)(66946007)(8936002)(8676002)(26005)(2906002)(16526019)(186003)(36756003)(44832011)(5660300002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR08MB3997;H:VI1PR08MB2765.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ahPYQKSyVN2vAufUriyOjN41FfB4hX3TrIzk8ONQyoaHmeW8nr2ZalKXUdcryXDupzSfep29UMEDe/Vn+DxNvP+NsMbTa9jpNHwqsAARNKMFly9uuFHd3Y/JQOg2X8Lo3cHPjRARYOMMuE9m28MqXGrc1JeILduZNMrtBeimPeywofydbouOLtu1Vo1BK3CNA/fDsSBfCqRGaEiZHGjZsqzrli3INdAw+Y8qL7l97VX0NRro5SjR8weTJDS1oZylrPXKCrW8v6fnw+I+z5d9VpHTaHlTkpXidOQA6Y5eDwPfv+jODmKEFNsq7w+t9B1aVuyohtVsLyU7nLO9foHTzJeDIriaHyVXWtlmbuUNCbZT9EgrKodAt7CmWeHVX4LWmHv1+vyhqP9y5L/S1rqz0u1R5IfN/O7UhCj8cbv/wCmt+5brEAwfPYVZhRG+8p8q x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Andrea.Corallo@arm.com; Return-Path: Andrea.Corallo@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 70aeb22d-6988-414c-7632-08d79ff56e82 X-SW-Source: 2020-01/txt/msg01565.txt.bz2 > Andrea Corallo writes: > >> Andrea Corallo writes: >> >>> Andrea Corallo writes: >>> >>>> Hi all, >>>> yesterday I've found an interesting bug in libgccjit. >>>> Seems we have an hard limitation of 200 characters for literal strings. >>>> Attempting to create longer strings lead to ICE during pass_expand >>>> while performing a sanity check in get_constant_size. >>>> >>>> Tracking down the issue seems the code we have was inspired from >>>> c-family/c-common.c:c_common_nodes_and_builtins were array_domain_type >>>> is actually defined with a size of 200. >>>> The comment that follows that point sounded premonitory :) :) >>>> >>>> /* Make a type for arrays of characters. >>>> With luck nothing will ever really depend on the length of this >>>> array type. */ >>>> >>>> At least in the current implementation the type is set by >>>> fix_string_type were the actual string length is taken in account. >>>> >>>> I attach a patch updating the logic accordingly and a new testcase >>>> for that. >>>> >>>> make check-jit is passing clean. >>>> >>>> Best Regards >>>> Andrea >>>> >>>> gcc/jit/ChangeLog >>>> 2019-??-?? Andrea Corallo >>>> >>>> * jit-playback.h >>>> (gcc::jit::recording::context m_recording_ctxt): Remove >>>> m_char_array_type_node field. >>>> * jit-playback.c >>>> (playback::context::context) Remove m_char_array_type_node from member >>>> initializer list. >>>> (playback::context::new_string_literal) Fix logic to handle string >>>> length > 200. >>>> >>>> gcc/testsuite/ChangeLog >>>> 2019-??-?? Andrea Corallo >>>> >>>> * jit.dg/all-non-failing-tests.h: Add test-long-string-literal.c. >>>> * jit.dg/test-long-string-literal.c: New testcase. >>>> diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c >>>> index 9eeb2a7..a26b8d3 100644 >>>> --- a/gcc/jit/jit-playback.c >>>> +++ b/gcc/jit/jit-playback.c >>>> @@ -88,7 +88,6 @@ playback::context::context (recording::context *ctxt) >>>> : log_user (ctxt->get_logger ()), >>>> m_recording_ctxt (ctxt), >>>> m_tempdir (NULL), >>>> - m_char_array_type_node (NULL), >>>> m_const_char_ptr (NULL) >>>> { >>>> JIT_LOG_SCOPE (get_logger ()); >>>> @@ -670,9 +669,12 @@ playback::rvalue * >>>> playback::context:: >>>> new_string_literal (const char *value) >>>> { >>>> - tree t_str =3D build_string (strlen (value), value); >>>> - gcc_assert (m_char_array_type_node); >>>> - TREE_TYPE (t_str) =3D m_char_array_type_node; >>>> + /* Compare with c-family/c-common.c: fix_string_type. */ >>>> + size_t len =3D strlen (value); >>>> + tree i_type =3D build_index_type (size_int (len)); >>>> + tree a_type =3D build_array_type (char_type_node, i_type); >>>> + tree t_str =3D build_string (len, value); >>>> + TREE_TYPE (t_str) =3D a_type; >>>> >>>> /* Convert to (const char*), loosely based on >>>> c/c-typeck.c: array_to_pointer_conversion, >>>> @@ -2703,10 +2705,6 @@ playback::context:: >>>> replay () >>>> { >>>> JIT_LOG_SCOPE (get_logger ()); >>>> - /* Adapted from c-common.c:c_common_nodes_and_builtins. */ >>>> - tree array_domain_type =3D build_index_type (size_int (200)); >>>> - m_char_array_type_node >>>> - =3D build_array_type (char_type_node, array_domain_type); >>>> >>>> m_const_char_ptr >>>> =3D build_pointer_type (build_qualified_type (char_type_node, >>>> diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h >>>> index d4b148e..801f610 100644 >>>> --- a/gcc/jit/jit-playback.h >>>> +++ b/gcc/jit/jit-playback.h >>>> @@ -322,7 +322,6 @@ private: >>>> >>>> auto_vec m_functions; >>>> auto_vec m_globals; >>>> - tree m_char_array_type_node; >>>> tree m_const_char_ptr; >>>> >>>> /* Source location handling. */ >>>> diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsu= ite/jit.dg/all-non-failing-tests.h >>>> index 0272e6f8..1b3d561 100644 >>>> --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h >>>> +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h >>>> @@ -220,6 +220,13 @@ >>>> #undef create_code >>>> #undef verify_code >>>> >>>> +/* test-long-string-literal.c */ >>>> +#define create_code create_code_long_string_literal >>>> +#define verify_code verify_code_long_string_literal >>>> +#include "test-long-string-literal.c" >>>> +#undef create_code >>>> +#undef verify_code >>>> + >>>> /* test-sum-of-squares.c */ >>>> #define create_code create_code_sum_of_squares >>>> #define verify_code verify_code_sum_of_squares >>>> diff --git a/gcc/testsuite/jit.dg/test-long-string-literal.c b/gcc/tes= tsuite/jit.dg/test-long-string-literal.c >>>> new file mode 100644 >>>> index 0000000..882567c >>>> --- /dev/null >>>> +++ b/gcc/testsuite/jit.dg/test-long-string-literal.c >>>> @@ -0,0 +1,48 @@ >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> +#include "libgccjit.h" >>>> + >>>> +#include "harness.h" >>>> + >>>> +const char very_long_string[] =3D >>>> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc= abcabcabc" >>>> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc= abcabcabc" >>>> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc= abcabcabc" >>>> + "abcabcabcabcabcabcabcabcabcabca"; >>>> + >>>> +void >>>> +create_code (gcc_jit_context *ctxt, void *user_data) >>>> +{ >>>> + /* Build the test_fn. */ >>>> + gcc_jit_function *f =3D >>>> + gcc_jit_context_new_function ( >>>> + ctxt, NULL, >>>> + GCC_JIT_FUNCTION_EXPORTED, >>>> + gcc_jit_context_get_type(ctxt, >>>> + GCC_JIT_TYPE_CONST_CHAR_PTR), >>>> + "test_long_string_literal", >>>> + 0, NULL, 0); >>>> + gcc_jit_block *blk =3D >>>> + gcc_jit_function_new_block (f, "init_block"); >>>> + gcc_jit_rvalue *res =3D >>>> + gcc_jit_context_new_string_literal (ctxt, very_long_string); >>>> + >>>> + gcc_jit_block_end_with_return (blk, NULL, res); >>>> +} >>>> + >>>> +void >>>> +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) >>>> +{ >>>> + typedef const char *(*fn_type) (void); >>>> + CHECK_NON_NULL (result); >>>> + fn_type test_long_string_literal =3D >>>> + (fn_type)gcc_jit_result_get_code (result, "test_long_string_liter= al"); >>>> + CHECK_NON_NULL (test_long_string_literal); >>>> + >>>> + /* Call the JIT-generated function. */ >>>> + const char *str =3D test_long_string_literal (); >>>> + CHECK_NON_NULL (str); >>>> + CHECK_VALUE (strcmp (str, very_long_string), 0); >>>> +} >>> >>> Kindly pinging >>> >>> Bests >>> Andrea >> >> Hi, >> I'd like to ping this patch. >> >> Bests >> Andrea > > Pinging again. > > Bests > Andrea > ---------- Ping