public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8585] c++: fix SIGFPE with -Wclass-memaccess [PR105634] Date: Tue, 19 Jul 2022 18:25:46 +0000 (GMT) [thread overview] Message-ID: <20220719182546.87E953858C52@sourceware.org> (raw) https://gcc.gnu.org/g:deafa40eb57b39626e116ca6a15d34a34c57c9f6 commit r12-8585-gdeafa40eb57b39626e116ca6a15d34a34c57c9f6 Author: Marek Polacek <polacek@redhat.com> Date: Tue Jul 19 14:24:25 2022 -0400 c++: fix SIGFPE with -Wclass-memaccess [PR105634] Here we crash because we attempt to % by 0. Thus fixed. PR c++/105634 gcc/cp/ChangeLog: * call.cc (maybe_warn_class_memaccess): Avoid % by zero. gcc/testsuite/ChangeLog: * g++.dg/warn/Wclass-memaccess-7.C: New test. Diff: --- gcc/cp/call.cc | 2 ++ gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 726770d4db8..af92a961000 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -10333,6 +10333,8 @@ maybe_warn_class_memaccess (location_t loc, tree fndecl, /* Finally, warn on partial copies. */ unsigned HOST_WIDE_INT typesize = tree_to_uhwi (TYPE_SIZE_UNIT (desttype)); + if (typesize == 0) + break; if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize) warned = warning_at (loc, OPT_Wclass_memaccess, (typesize - partial > 1 diff --git a/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C new file mode 100644 index 00000000000..7e86b248629 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C @@ -0,0 +1,13 @@ +// PR c++/105634 +// { dg-do compile { target { c++11 } } } +// { dg-options "-Wall" } + +struct s +{ + struct {} a[] = 1.0; // { dg-error "" } + void f (char *c) + { + s s; + __builtin_memcpy (&s, c, sizeof(s)); + } +};
reply other threads:[~2022-07-19 18:25 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=20220719182546.87E953858C52@sourceware.org \ --to=mpolacek@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).