This is the mail archive of the
mailing list for the GCC project.
Re: strlen optimizations based on whether stpcpy is declared?
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Alan Modra <amodra at gmail dot com>, GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Mon, 2 Oct 2017 17:06:13 +0200
- Subject: Re: strlen optimizations based on whether stpcpy is declared?
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7E3781E18
- References: <email@example.com> <20171002071153.GR1701@tucnak> <20171002103506.GT25070@bubble.grove.modra.org> <20171002104056.GU1701@tucnak> <firstname.lastname@example.org>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Oct 02, 2017 at 09:00:41AM -0600, Martin Sebor wrote:
> Thanks. That makes sense to me. The wrinkle with this approach
> is that the same code (same function) has different effects on
> the compiler (as in, is subject to different optimization
> decisions, or can cause false positives/negatives) depending
> whether some unrelated code (in another function) calls
> __builtin_stpcpy or calls (and declares) stpcpy, or does neither.
> This is probably not very common in application programs but it
> does happen often in the GCC test suite (this is the second time
> I've been bitten by it in just a few months).
Why is that a problem? In most user code, people just
#include <string.h> or #include <cstring> and depending on feature
test macros, either stpcpy is available, or not.
For GCC testsuite the tests that specially test for these transformations
have or intentionally don't have the stpcpy prototype available.
> IIUC, ideally, the decision whether or not to make
> the transformation would be based on whether stpcpy is called
> by the function on the result of a prior strcpy/strcat. A less
I don't understand this suggestion. Usually there is no stpcpy call
anywhere, we still want to make the transformation if we can assume
the library provides it. So you'd penalize a lot of code for no benefit.