From patchwork Sun Sep 12 15:49:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1526923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Xi4+xQxq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H6vFr75NJz9sXS for ; Mon, 13 Sep 2021 01:50:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E8293858434 for ; Sun, 12 Sep 2021 15:50:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E8293858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631461820; bh=YP1HBLWMVpBjrP4GQEkM+zR4t/gnizsmGedMHr1DImo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Xi4+xQxqIVXzFCuzVJ46ID+g6ksfCzVafvvqSJ2TqfG8HSYYjH90YrY7reuwZAmB8 G3sKhSwzXN7mSg1jzx1JL3LPHpEVJtIkguWymh2/9DXr4+Y60mKT/mmX1iofmhPxTC 24KLlCok8E4nnBg94SqYzbYvgex5VvplWsCkqZ74= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id AC88D3858408 for ; Sun, 12 Sep 2021 15:49:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC88D3858408 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4H6vDw6z5bzQjPk; Sun, 12 Sep 2021 17:49:36 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de To: gcc-patches@gcc.gnu.org Subject: [committed] d: Don't include terminating null pointer in string expression conversion (PR102185) Date: Sun, 12 Sep 2021 17:49:29 +0200 Message-Id: <20210912154929.197505-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: DB61417FC X-Spam-Status: No, score=-15.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes an issue with the routine that converts STRING_CST to a StringExp for the dmd front-end to use during the semantic pass. The null terminator gets re-added by the ExprVisitor when lowering StringExp back into a STRING_CST during the code generator pass. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, committed to mainline and backported to the releases/gcc-11 branch. Regards, Iain. --- gcc/d/ChangeLog: PR d/102185 * d-builtins.cc (d_eval_constant_expression): Don't include terminating null pointer in string expression conversion. gcc/testsuite/ChangeLog: PR d/102185 * gdc.dg/pr102185.d: New test. --- gcc/d/d-builtins.cc | 2 +- gcc/testsuite/gdc.dg/pr102185.d | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gdc.dg/pr102185.d diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index ab39d69c294..33347a14c67 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -380,7 +380,7 @@ d_eval_constant_expression (const Loc &loc, tree cst) else if (code == STRING_CST) { const void *string = TREE_STRING_POINTER (cst); - size_t len = TREE_STRING_LENGTH (cst); + size_t len = TREE_STRING_LENGTH (cst) - 1; return StringExp::create (loc, CONST_CAST (void *, string), len); } else if (code == VECTOR_CST) diff --git a/gcc/testsuite/gdc.dg/pr102185.d b/gcc/testsuite/gdc.dg/pr102185.d new file mode 100644 index 00000000000..39823a3c556 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr102185.d @@ -0,0 +1,7 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102185 +// { dg-do compile } + +static assert(__traits(getTargetInfo, "floatAbi").length == 0 || + __traits(getTargetInfo, "floatAbi") == "hard" || + __traits(getTargetInfo, "floatAbi") == "soft" || + __traits(getTargetInfo, "floatAbi") == "softfp");