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 | |
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')
-rw-r--r-- | gcc/cp/call.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-2.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess-2.C) | 0 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-3.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess-3.C) | 0 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-4.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess-4.C) | 0 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-5.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess-5.C) | 0 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-6.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess-6.C) | 0 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wclass-memaccess.C (renamed from gcc/testsuite/g++.dg/Wclass-memaccess.C) | 0 |
8 files changed, 15 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 diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-2.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-2.C index f138b8b..f138b8b 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess-2.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-2.C diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-3.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-3.C index 36e0e68..36e0e68 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess-3.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-3.C diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-4.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-4.C index 69b8c78..69b8c78 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess-4.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-4.C diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-5.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-5.C index d0fffea..d0fffea 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess-5.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-5.C diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-6.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-6.C index 7f6fe03..7f6fe03 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess-6.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-6.C 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 0000000..7e86b24 --- /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)); + } +}; diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess.C b/gcc/testsuite/g++.dg/warn/Wclass-memaccess.C index 1dc23df..1dc23df 100644 --- a/gcc/testsuite/g++.dg/Wclass-memaccess.C +++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess.C |