public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/57627] New: -Wsizeof-pointer-memaccess should make an exception for character types
@ 2013-06-15 18:46 harald at gigawatt dot nl
  2013-06-26 16:43 ` [Bug c/57627] " harald at gigawatt dot nl
  0 siblings, 1 reply; 2+ messages in thread
From: harald at gigawatt dot nl @ 2013-06-15 18:46 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 5135 bytes --]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57627

            Bug ID: 57627
           Summary: -Wsizeof-pointer-memaccess should make an exception
                    for character types
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: harald at gigawatt dot nl

$ cat test.c
void f1(int *dst, int *src)
{ __builtin_memcpy(dst, src, sizeof(int *)); }

void f2(char *dst, char *src)
{ __builtin_memcpy(dst, src, sizeof(char *)); }

void f3(unsigned char *dst, unsigned char *src)
{ __builtin_memcpy(dst, src, sizeof(unsigned char *)); }
$ gcc -c test.c -Wall
test.c: In function ‘f1’:
test.c:2:36: warning: argument to ‘sizeof’ in ‘__builtin_memcpy’ call is the
same pointer type ‘int *’ as the destination; expected ‘int’ or an explicit
length [-Wsizeof-pointer-memaccess]
 { __builtin_memcpy(dst, src, sizeof(int *)); }
                                    ^
test.c: In function ‘f2’:
test.c:5:36: warning: argument to ‘sizeof’ in ‘__builtin_memcpy’ call is the
same pointer type ‘char *’ as the destination; expected ‘char’ or an explicit
length [-Wsizeof-pointer-memaccess]
 { __builtin_memcpy(dst, src, sizeof(char *)); }
                                    ^
test.c: In function ‘f3’:
test.c:8:36: warning: argument to ‘sizeof’ in ‘__builtin_memcpy’ call is the
same pointer type ‘unsigned char *’ as the destination; expected ‘unsigned
char’ or an explicit length [-Wsizeof-pointer-memaccess]
 { __builtin_memcpy(dst, src, sizeof(unsigned char *)); }
                                    ^
$ gcc --version
gcc (GCC) 4.8.1 20130603 (Red Hat 4.8.1-1)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The warning makes sense for most types (f1), but for character types, I don't
think GCC should give any warning (f2 and f3). I'm seeing this warning for
correct code that stores pointers in raw byte buffers, and I would be surprised
if that is less common than code that really means to memcpy a single byte.
>From gcc-bugs-return-424436-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Jun 15 19:25:38 2013
Return-Path: <gcc-bugs-return-424436-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 20957 invoked by alias); 15 Jun 2013 19:25:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 20902 invoked by uid 48); 15 Jun 2013 19:25:32 -0000
From: "amylaar at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/57425] [4.8/4.9 regression] RTL alias analysis unprepared to handle stack slot sharing
Date: Sat, 15 Jun 2013 19:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: rtl-optimization
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: major
X-Bugzilla-Who: amylaar at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.2
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-57425-4-So9On2RRN5@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57425-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57425-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-06/txt/msg00815.txt.bz2
Content-length: 916

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW425

--- Comment #7 from Jorn Wolfgang Rennecke <amylaar at gcc dot gnu.org> ---
Created attachment 30310
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id0310&actioníit
patch for alias problem during cse pass

(In reply to Richard Biener from comment #4)
> Note that I only recently fixed a wrong alias query from using
> true_dependence
> to anti_dependence.  Similar issues may exist elsewhere.

Indeed, looking at the .172r.cse1 dump more closely, I saw it
actually contained actually two dumps, first looking OK, the
second with the deleterious changes in place.

First, cse is applied to the asms.  I'm not sure if this should
be called a bug or a feature.
At any rate, cse does have an alias problem as you suspected.
The attached patch addresses this issue, but doesn't fix the testcase;
something goes again wrong between the reload and postreload dump.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/57627] -Wsizeof-pointer-memaccess should make an exception for character types
  2013-06-15 18:46 [Bug c/57627] New: -Wsizeof-pointer-memaccess should make an exception for character types harald at gigawatt dot nl
@ 2013-06-26 16:43 ` harald at gigawatt dot nl
  0 siblings, 0 replies; 2+ messages in thread
From: harald at gigawatt dot nl @ 2013-06-26 16:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57627

--- Comment #1 from Harald van Dijk <harald at gigawatt dot nl> ---
I just realised the very similar example

void f4(char *dst, char *src)
{ __builtin_memcpy(dst, src, sizeof(src)); }

void f5(unsigned char *dst, unsigned char *src)
{ __builtin_memcpy(dst, src, sizeof(src)); }

also gets a warning, but in that case, I fully agree with the warning GCC
currently gives. So, to clarify, my request/suggestion is *only* to suppress
the warning for f2 and f3 in my report, and leave the behaviour for these f4
and f5 as it is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-26 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-15 18:46 [Bug c/57627] New: -Wsizeof-pointer-memaccess should make an exception for character types harald at gigawatt dot nl
2013-06-26 16:43 ` [Bug c/57627] " harald at gigawatt dot nl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).