diff options
author | Marek Polacek <polacek@redhat.com> | 2022-05-17 15:13:58 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-05-18 10:33:13 -0400 |
commit | dfe38b8d5dbfe3dd5209aece4ce2f7a6b303a2f9 (patch) | |
tree | ce63010fef0197b72f8ee4a5243eeffb3feb6d8c /gcc/cp/call.cc | |
parent | 0d189b16f81fb9dced0b29495b5d100492b779d8 (diff) | |
download | gcc-dfe38b8d5dbfe3dd5209aece4ce2f7a6b303a2f9.zip gcc-dfe38b8d5dbfe3dd5209aece4ce2f7a6b303a2f9.tar.gz gcc-dfe38b8d5dbfe3dd5209aece4ce2f7a6b303a2f9.tar.bz2 |
c++: fix SIGFPE with -Wclass-memaccess [PR105634]
Here we crash because we attempt to % by 0. Thus fixed.
While at it, I've moved the -Wclass-memaccess tests into warn/.
I've checked that the # of expected passes is the same before/after
the move.
PR c++/105634
gcc/cp/ChangeLog:
* call.cc (maybe_warn_class_memaccess): Avoid % by zero.
gcc/testsuite/ChangeLog:
* g++.dg/Wclass-memaccess-2.C: Moved to...
* g++.dg/warn/Wclass-memaccess-2.C: ...here.
* g++.dg/Wclass-memaccess-3.C: Moved to...
* g++.dg/warn/Wclass-memaccess-3.C: ...here.
* g++.dg/Wclass-memaccess-4.C: Moved to...
* g++.dg/warn/Wclass-memaccess-4.C: ...here.
* g++.dg/Wclass-memaccess-5.C: Moved to...
* g++.dg/warn/Wclass-memaccess-5.C: ...here.
* g++.dg/Wclass-memaccess-6.C: Moved to...
* g++.dg/warn/Wclass-memaccess-6.C: ...here.
* g++.dg/Wclass-memaccess.C: Moved to...
* g++.dg/warn/Wclass-memaccess.C: ...here.
* g++.dg/warn/Wclass-memaccess-7.C: New test.
Diffstat (limited to 'gcc/cp/call.cc')
-rw-r--r-- | gcc/cp/call.cc | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 0240e36..14c6037 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -10329,6 +10329,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 |