From dfe38b8d5dbfe3dd5209aece4ce2f7a6b303a2f9 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 17 May 2022 15:13:58 -0400 Subject: 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. --- gcc/cp/call.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/cp/call.cc') 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 -- cgit v1.1