From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4A0BC385DC29; Wed, 1 Apr 2020 16:05:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A0BC385DC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585757135; bh=LXzmE9Ga5rP4zINCCAyAYQ+RChuTFZdxd6z4AmKGgFc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HqG/tYyYFRvLqpvCYffR5XW53Z9Atnt36g4P4wdExYp/ucYqMsdpGloLBNuGOj66K LJcEoCXO0TGlgerJzl63Bm/N43nbOONWeHWazjSS75DU+fkILTokNa1pALqNpPs5Rz 688njgwQeAl1ewKUKXzkyWk3OJFLzy+ZTxUK02mc= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/94444] __attribute__((access(...))) ignored for memcpy when compiling with -Os Date: Wed, 01 Apr 2020 16:05:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on cc everconfirmed bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 16:05:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94444 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2020-04-01 CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 Status|UNCONFIRMED |WAITING --- Comment #2 from Martin Sebor --- Can you include a small test case that reproduce the problem (and the full command line used to reproduce it)? I can't think of a reason why the attribute would be completely ineffective with -Os and a simple test case confirms it does the right thing even with with -fno-builtin-memcpy (if the built-in happens to be disabled while building libc). GCC recognizes __builtin_memcpy as special (built-ins aren't decorated with the attribute = in GCC 10) so it should have the same detection as functions explicitly declar= ed with the attribute. $ cat z.c && gcc -Os -S -fno-builtin-memcpy z.c __attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void* memcpy (void*, const void*, __SIZE_TYPE__); char a[3]; void f (const void *s) { memcpy (a, s, 5); } void g (const void *s) { __builtin_memcpy (a, s, 5); } z.c: In function =E2=80=98f=E2=80=99: z.c:8:3: warning: =E2=80=98memcpy=E2=80=99 writing 5 bytes into a region of= size 3 overflows the destination [-Wstringop-overflow=3D] 8 | memcpy (a, s, 5); | ^~~~~~~~~~~~~~~~ z.c:2:7: note: in a call to function =E2=80=98memcpy=E2=80=99 declared with= attribute =E2=80=98write_only (1, 3)=E2=80=99 2 | void* memcpy (void*, const void*, __SIZE_TYPE__); | ^~~~~~ z.c: In function =E2=80=98g=E2=80=99: z.c:13:3: warning: =E2=80=98__builtin_memcpy=E2=80=99 writing 5 bytes into = a region of size 3 overflows the destination [-Wstringop-overflow=3D] 13 | __builtin_memcpy (a, s, 5); | ^~~~~~~~~~~~~~~~~~~~~~~~~~=