From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124807 invoked by alias); 30 Sep 2019 09:18:49 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 124784 invoked by uid 89); 30 Sep 2019 09:18:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-22.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=Kindly, replay X-Spam-Status: No, score=-22.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50058.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Sep 2019 09:18:45 +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=Y1bPBg7yKqeVplqLfONzyfEWEKnDh8a8fEsmmYbDpno=; b=pq3CdW9Jkp/StQED6efHYyUEne1vseJ0VpgBaouDhWs3V38oOQBkcUuNf/KjYjR6MbUk9jfbiZtPaNB6IXEu+iIl3qMOyn0WCCfvIdRuJGgsDLrwGsAXnbIWfx9ROzvsKvgVQOtcoAZAt355z4wz6CUDGmdoo7LSRaz4NkTKV8M= Received: from VI1PR0802CA0027.eurprd08.prod.outlook.com (2603:10a6:800:a9::13) by DBBPR08MB4773.eurprd08.prod.outlook.com (2603:10a6:10:d9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 09:18:40 +0000 Received: from AM5EUR03FT034.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::206) by VI1PR0802CA0027.outlook.office365.com (2603:10a6:800:a9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.17 via Frontend Transport; Mon, 30 Sep 2019 09:18:40 +0000 Authentication-Results: spf=fail (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=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 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 AM5EUR03FT034.mail.protection.outlook.com (10.152.16.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.15 via Frontend Transport; Mon, 30 Sep 2019 09:18:40 +0000 Received: ("Tessian outbound 851a1162fca7:v33"); Mon, 30 Sep 2019 09:18:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 833dfff13b884a8d X-CR-MTA-TID: 64aa7808 Received: from f1943ac4e495.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.4.58]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id A7AF761B-40E8-4C3F-AED5-AFA90BDD2435.1; Mon, 30 Sep 2019 09:18:31 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2058.outbound.protection.outlook.com [104.47.4.58]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f1943ac4e495.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 30 Sep 2019 09:18:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mw4js3phJwoGTZoNHC3Nvty3vUpiTbG4Wx0M1FaK8sEQljXHTYv1LWTu/gjkoOQMIythhpjo1nGzqxeCLWYZrOHk4EEq7Gla/uy7u953ROGuXjpxxuVtD9oADq0U89b5wAb0ZwrC6+WoY4ItMQK4Kns2apqr6PcMS8MyWM0uLWGkVNInw/EO9zbEWTZoOW9HGsqBBOXyDnj+4ECHSevTysfPiSuSrtXmQCzAHVxYN9/WlTpurtdQ9uzwRyspvxujxJcPLHGJIpZHIZzn7BF5gjWFn8Hif1BLW8uKjnNQj6+hPkKiJPl5n9zuMYMKrwitQ1iuLOaiYuW4dWsTVbTlqQ== 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=Y1bPBg7yKqeVplqLfONzyfEWEKnDh8a8fEsmmYbDpno=; b=h7hYz30gfluTL5sqs9GaGHdxl7sj/SP51bgS4WpuVwCDNkWlPU11thm36nOKY0O2vCKwYYnME0bje6JV1L8Xh8Y3o0kXQbqaU3vZ99KvEvEfUy8n5Oh2Ee0P3E6JYcylV6PTU/8J/SmDZWOByeUTWjC5Fa2aPNUOgB21SMQybBOKhwBVKX3WtiIHVGz05j8hODBrfxde4e1wbQCH7lvBdi7yqPdc3uf2EQFlhhWtJRbs1+erMz3E7VHspm9zIl6ErNZ9aIitjaGyPVsudY1ccS9Qiq3Y7mP5cyOEi7ouEEx24PsCTIiLdxSxxmzjabOo+OcAhETME5lHib7fNiEtxw== 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=Y1bPBg7yKqeVplqLfONzyfEWEKnDh8a8fEsmmYbDpno=; b=pq3CdW9Jkp/StQED6efHYyUEne1vseJ0VpgBaouDhWs3V38oOQBkcUuNf/KjYjR6MbUk9jfbiZtPaNB6IXEu+iIl3qMOyn0WCCfvIdRuJGgsDLrwGsAXnbIWfx9ROzvsKvgVQOtcoAZAt355z4wz6CUDGmdoo7LSRaz4NkTKV8M= Received: from VE1PR08MB5070.eurprd08.prod.outlook.com (20.179.31.87) by VE1PR08MB4895.eurprd08.prod.outlook.com (10.255.114.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Mon, 30 Sep 2019 09:18:29 +0000 Received: from VE1PR08MB5070.eurprd08.prod.outlook.com ([fe80::60e4:d12f:de22:5043]) by VE1PR08MB5070.eurprd08.prod.outlook.com ([fe80::60e4:d12f:de22:5043%7]) with mapi id 15.20.2284.028; Mon, 30 Sep 2019 09:18:29 +0000 From: Andrea Corallo To: David Malcolm CC: Andrea Corallo , "jit@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" , nd Subject: Re: [PATCH][gcc] libgccjit: handle long literals in playback::context::new_string_literal Thread-Topic: [PATCH][gcc] libgccjit: handle long literals in playback::context::new_string_literal Thread-Index: AQHVYW8dCMmJW7HrCU6PDNsvcxXHiKcjeB6AgCCk5QA= Date: Tue, 01 Jan 2019 00:00:00 -0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0233.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::29) To VE1PR08MB5070.eurprd08.prod.outlook.com (2603:10a6:803:10c::23) Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Andrea.Corallo@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [217.140.96.140] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: 643c572b-c021-489d-d92e-08d745872ec2 X-MS-Office365-Filtering-HT: Tenant X-MS-TrafficTypeDiagnostic: VE1PR08MB4895:|VE1PR08MB4895:|DBBPR08MB4773: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6790;OLM:6790; x-forefront-prvs: 01762B0D64 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(39850400004)(136003)(346002)(396003)(376002)(366004)(54534003)(189003)(199004)(53754006)(71190400001)(76176011)(71200400001)(6512007)(86362001)(6246003)(5660300002)(4326008)(66066001)(36756003)(486006)(2616005)(476003)(256004)(11346002)(446003)(14444005)(5024004)(6486002)(6436002)(25786009)(386003)(6506007)(26005)(102836004)(66946007)(66476007)(66556008)(64756008)(66446008)(186003)(52116002)(44832011)(99286004)(229853002)(3846002)(6116002)(478600001)(6916009)(81166006)(8676002)(14454004)(8936002)(81156014)(54906003)(316002)(305945005)(7736002)(2906002)(4226003);DIR:OUT;SFP:1101;SCL:1;SRVR:VE1PR08MB4895;H:VE1PR08MB5070.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: dJU1Vg/BKDUBUgQPKkSKP3l8LkO7D5duykh9nO9ubRfYEjif9gT2m58sGxzDoEqj6m0QPz0Gsy796rxLpb6TOgAQmbO2TXJS80b1yziID/FMmdA48BN3CCBlhZmiU2EnR1AFFgQMhjk5W3Z2bXIMMtpLip9Js6aUZi2pw7OTRsacjPPb0dess1LrMCjL6kBa0BGGJJYMMg1JBp6/7u3vEPsd+j3AKopS836xr/FEOSGSHnvj1D+qoSBMROc8zkCuP2jP+X/3DQqZ4zsitGBYGN0q9WZDR5K8KFNrjSwIobtY2/nudw/efWxxXZd+GH0JeOgtOZKSW/G1jDd/jmR6NQGp4aaSIMmjmQzq+LztGQpfapWeIuIgPFt6oSB4FRYStazC6K342SUaH4M/cq5MGQ7O8fb+yKMdnghAWYEoNmY= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4895 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Andrea.Corallo@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT034.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;IPV:CAL;SCL:-1;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(136003)(376002)(396003)(346002)(39850400004)(1110001)(339900001)(53754006)(189003)(199004)(54534003)(50466002)(26826003)(4326008)(23756003)(478600001)(8746002)(8936002)(229853002)(6512007)(14454004)(6116002)(6486002)(3846002)(2906002)(22756006)(81156014)(81166006)(8676002)(36756003)(6862004)(5660300002)(70586007)(70206006)(6246003)(76130400001)(105606002)(36906005)(86362001)(11346002)(356004)(126002)(476003)(450100002)(99286004)(5024004)(14444005)(486006)(25786009)(2616005)(336012)(76176011)(66066001)(7736002)(305945005)(54906003)(102836004)(446003)(186003)(316002)(26005)(6506007)(386003)(47776003)(4226003);DIR:OUT;SFP:1101;SCL:1;SRVR:DBBPR08MB4773;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:Fail;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;MX:1;A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 83348a52-6e5a-4e75-41be-08d7458727cb NoDisclaimer: True X-Forefront-PRVS: 01762B0D64 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YJHI1eKVEzrEF3BMLw+sJk+EntMALbwZhOJDLPTvr3TXju9+NiN2dda8s9H2QgLF/J6j3l2q6h8hy9BlDreeI9GEnPLHcG0+H8SWlfl86LaBYD/MfpBBMeDneaovYUVwZvnWRGAyYGirJ8EL1gz2Adnji51fR0WfsS2IIqII9cQ5ocDczoG5vea1NL/apPhkalzmgdgOS6U7vJi8P4EneUV17/XQCpMlJsRW6MWV8BRmYLQfo1/ciysBo/758Z/Y7NImS2u13wXJMA/K7DZukIPHdMfVenRvbks9cbJgyw5drUlc86qtM9uH9xy0K5KNWD0wFy94XcZDXb/L6yndS0AW0qUu2+mEp7S3qq0kRC2QgXLdTEqH9EW2x7xHvjTSV4dYU0U4CyZJRYAO51ocbvMk2AWT47bSfhlOaDi7cDs= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2019 09:18:40.2876 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 643c572b-c021-489d-d92e-08d745872ec2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4773 X-SW-Source: 2019-q3/txt/msg00016.txt.bz2 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/testsuit= e/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/tests= uite/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 >> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab= cabcabc" >> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab= cabcabc" >> + "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab= cabcabc" >> + "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_literal= "); >> + 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