public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Sebor <msebor@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8600] Backported from trunk: Date: Thu, 17 Jun 2021 20:07:48 +0000 (GMT) [thread overview] Message-ID: <20210617200748.271693985466@sourceware.org> (raw) https://gcc.gnu.org/g:c2791cd4e62731ccde165c0e62b83f8e7ee38118 commit r11-8600-gc2791cd4e62731ccde165c0e62b83f8e7ee38118 Author: Martin Sebor <msebor@redhat.com> Date: Thu Jun 17 10:24:34 2021 -0600 Backported from trunk: PR middle-end/100307 - spurious -Wplacement-new with negative pointer offset gcc/ChangeLog: PR middle-end/100307 * builtins.c (compute_objsize_r): Clear base0 for pointers. gcc/testsuite/ChangeLog: PR middle-end/100307 * g++.dg/warn/Wplacement-new-size-9.C: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-26.c: New test. Diff: --- gcc/builtins.c | 4 ++- gcc/testsuite/g++.dg/warn/Wplacement-new-size-9.C | 39 ++++++++++++++++++++++ .../gcc.dg/tree-ssa/builtin-sprintf-warn-26.c | 38 +++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 308846ee39b..1bfffe7081b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5451,8 +5451,10 @@ compute_objsize_r (tree ptr, int ostype, access_ref *pref, if (!addr && POINTER_TYPE_P (TREE_TYPE (ptr))) { /* Set the maximum size if the reference is to the pointer - itself (as opposed to what it points to). */ + itself (as opposed to what it points to), and clear + BASE0 since the offset isn't necessarily zero-based. */ pref->set_max_size_range (); + pref->base0 = false; return true; } diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-9.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-9.C new file mode 100644 index 00000000000..a6b5870be64 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-9.C @@ -0,0 +1,39 @@ +/* PR middle-end/100307 - spurious -Wplacement-new with negative pointer + offset + { dg-do compile } + { dg-options "-O0 -Wall" } */ + +void* operator new (__SIZE_TYPE__, void *p) { return p; } +void* operator new[] (__SIZE_TYPE__, void *p) { return p; } + +static char a[2]; + +void* nowarn_scalar () +{ + char* p = a + 1; + char *q = new (p - 1) char (); // { dg-bogus "-Wplacement-new" } + return q; +} + + +void* nowarn_array () +{ + char* p = a + 1; + char *q = new (p - 1) char[2]; // { dg-bogus "-Wplacement-new" } + return q; +} + +void* warn_scalar () +{ + char* p = a + 1; + char *q = new (p - 2) char (); // { dg-warning "-Wplacement-new" "pr100325" { xfail *-*-* } } + return q; +} + + +void* warn_array () +{ + char* p = a + 1; + char *q = new (p - 1) char[2]; // { dg-warning "-Wplacement-new" "pr100325" { xfail *-*-* } } + return q; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-26.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-26.c new file mode 100644 index 00000000000..16a551d9c8d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-26.c @@ -0,0 +1,38 @@ +/* PR middle-end/100307 - spurious -Wplacement-new with negative pointer + offset + { dg-do compile } + { dg-options "-O0 -Wall" } */ + +extern int sprintf (char*, const char*, ...); + +char a[4]; + +void nowarn_1m1 () +{ + char *p = a + 1; + sprintf (p - 1, "%i", 123); // { dg-bogus "-Wformat-overflow" } +} + +void nowarn_4m3 () +{ + char *p = a + 4; + sprintf (p - 3, "%i", 12); // { dg-bogus "-Wformat-overflow" } +} + +void warn_2m1 () +{ + char *p = a + 2; + sprintf (p - 1, "%i", 123); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } } +} + +void warn_3m1 () +{ + char *p = a + 3; + sprintf (p - 1, "%i", 12); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } } +} + +void warn_4m1 () +{ + char *p = a + 4; + sprintf (p - 1, "%i", 1); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } } +}
reply other threads:[~2021-06-17 20:07 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210617200748.271693985466@sourceware.org \ --to=msebor@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).