public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dimhen at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102386] New: [12 regression] bogus -Wrestrict for unreachable memcpy()
Date: Fri, 17 Sep 2021 10:43:55 +0000	[thread overview]
Message-ID: <bug-102386-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102386

            Bug ID: 102386
           Summary: [12 regression] bogus -Wrestrict for unreachable
                    memcpy()
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dimhen at gmail dot com
  Target Milestone: ---

r12-3456 PASS
r12-3545 FAIL

$ cat x.i
static int GetHashParam_HP_OPAQUEBLOB_pdwDataLen = 0;
void *memcpy(void *, const void *, unsigned long);
typedef struct {
  int tSimpleBlobHeader;
  int bCurrKey[];
} CRYPT_OPAQUEHASHBLOB;
int GetHashParam_HP_OPAQUEBLOB() {
  CRYPT_OPAQUEHASHBLOB *pBlb;
  if (GetHashParam_HP_OPAQUEBLOB_pdwDataLen) {
    void *pcn = pBlb->bCurrKey, *pdwBuff = pBlb->bCurrKey;
    int dwDWBufLen = 8;
    memcpy(pcn, pdwBuff, sizeof(1) * dwDWBufLen);
  }
  return 1;
}

$ gcc -fpreprocessed -O --param max-early-inliner-iterations=2 -Wrestrict -c
x.i
x.i: In function 'GetHashParam_HP_OPAQUEBLOB':
x.i:12:5: warning: 'memcpy' accessing 32 bytes at offsets 4 and 4 overlaps 32
bytes at offset 4 [-Wrestrict]
   12 |     memcpy(pcn, pdwBuff, sizeof(1) * dwDWBufLen);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Test extracted from private codebase.
Key part:

static inline void foo(void *p, void *q, int N)
{
   if(p != q)
     memcpy(p, q, N);
}

void bar(void q, void p, int N)
{
   foo(p, q, N);
}

             reply	other threads:[~2021-09-17 10:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 10:43 dimhen at gmail dot com [this message]
2021-09-18 22:48 ` [Bug middle-end/102386] " msebor at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102386-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).