From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id D5AF03857010 for ; Tue, 7 Jul 2020 20:02:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D5AF03857010 Received: by mail-qv1-xf41.google.com with SMTP id el4so15320900qvb.13 for ; Tue, 07 Jul 2020 13:02:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Xdh8pGMXvKGO98Ra6V/Q86HzdLvlcItTb+HU5x3SQI8=; b=hE529eg8/yHRSJ4ZeZAcXBuL38YVIDMmo7/UCtxIvhD7GEZwtaImJMfiRadhaJaN0T RWRkkuxvONwMk+2PAMJZVl1rKgaOJMzMwyzIeUG7p8Wk5tlZzBSnxY0FNsypDYcP+fV3 lF1Vc2h58RVTdVT+RIpZiVrrOLUqIiba58ThOw+uel7gWoRYjlHgrO47kD57nMKhvxag XZaTshpFQnRnaQqtA0ql2um2hC4rqTZ3k1x0h631PLLM68Ck2Nc8Wc72zPWJQwMz5dKY a9VRlLHAm1/DXoZdA6vl4n0D3+SW1zFhxXjZyBEK0NSf7yePiI2KZj9eZ4pBVsopNVnO Q+TQ== X-Gm-Message-State: AOAM533mLZZna6K2pnczI6F2lTCJ+TNRW49deSubmB34EE3ow83ejnr8 5r4m0nKwuchUnjOFpwpQ4e8zL1DF X-Google-Smtp-Source: ABdhPJwjEt4ZrD4cxHzHHxkFXE/BLkWsTSb5358KCmD45/nLY5WhUBn/cDzwQvzzRRRiJQc5XCxzrg== X-Received: by 2002:ad4:4e07:: with SMTP id dl7mr52686829qvb.134.1594152162998; Tue, 07 Jul 2020 13:02:42 -0700 (PDT) Received: from [192.168.0.41] (184-96-233-25.hlrn.qwest.net. [184.96.233.25]) by smtp.gmail.com with ESMTPSA id s52sm27150953qtj.52.2020.07.07.13.02.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jul 2020 13:02:42 -0700 (PDT) Subject: Re: [PATCH] correct memcmp expansion of constant representations containing embedded nuls (PR 95189) From: Martin Sebor To: gcc-patches References: <546f1c1e-73f3-aa20-a3be-b7bae03fff55@gmail.com> Message-ID: <223dba96-ca1d-e3de-647f-461c773bf490@gmail.com> Date: Tue, 7 Jul 2020 14:02:35 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <546f1c1e-73f3-aa20-a3be-b7bae03fff55@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 07 Jul 2020 20:02:45 -0000 Ping: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549225.html On 6/30/20 6:23 PM, Martin Sebor wrote: > An enhancement to GCC 10 to improve the expansion of strncmp > calls with strings with embedded nuls introduced a regression > in similar calls to memcmp.  A review of the changes that led > up to the regression exposed a number of questionable choices > that likely conspired to cause the bug. > > For example, the name of the function with both the strncmp > enhancement as well as the memcmp bug is > inline_expand_builtin_string_cmp().  It's easy to assume that > the function handles calls to strcmp and strncmp but not also > memcmp. > > Another similar example is the name of the second c_getstr() > argument -- strlen -- that doesn't actually store the length > of the retrieved string but rather its size in bytes > (including any embedded nuls, but excluding those appended > implicitly to zero out the remainder of an array the string > is stored in, up to the array's size). > > Yet another example of a dubious choice is string_constant() > returning the empty string (i.e., STRING_CST with size 1) for > zero initializers of constants of any type (as opposed to one > of the same size as the constant object). > > Besides fixing the memcmp bug the attached patch (hopefully) > also rectifies some of the otherwise more or less benign > mistakes that precipitated it, mostly by clarifying comments > and changing misleading names of functions, their arguments, > or local variables. > > A happy consequence of the fixes is that they improve codegen > for calls to memcpy with constants whose representation includes > embedded nuls. > > Tested on x86_64-linux. > > Martin >