Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-07-05 Thread Martin Sebor
On 07/05/2017 02:58 PM, Andrew Pinski wrote: On Sun, Apr 30, 2017 at 1:02 PM, Pedro Alves wrote: Hi Martin, Thanks much for doing this. A few comments below, in light of my experience doing the equivalent checks in the gdb patch linked below, using standard C++11. On

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-07-05 Thread Andrew Pinski
On Sun, Apr 30, 2017 at 1:02 PM, Pedro Alves wrote: > Hi Martin, > > Thanks much for doing this. A few comments below, in light of my > experience doing the equivalent checks in the gdb patch linked below, > using standard C++11. > > On 04/29/2017 09:09 PM, Martin Sebor wrote:

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-07-04 Thread Richard Earnshaw (lists)
On 29/06/17 17:15, Jan Hubicka wrote: > Hello, >> diff --git a/gcc/hash-table.h b/gcc/hash-table.h >> index 0f7e21a..443d16c 100644 >> --- a/gcc/hash-table.h >> +++ b/gcc/hash-table.h >> @@ -803,7 +803,10 @@ hash_table::empty_slow () >>m_size_prime_index = nindex; >>

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-30 Thread Martin Sebor
On 06/30/2017 02:34 AM, Richard Biener wrote: On Thu, Jun 29, 2017 at 10:23 PM, Martin Sebor wrote: On 06/29/2017 10:15 AM, Jan Hubicka wrote: Hello, diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 0f7e21a..443d16c 100644 --- a/gcc/hash-table.h +++

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-30 Thread Richard Biener
On Thu, Jun 29, 2017 at 10:23 PM, Martin Sebor wrote: > On 06/29/2017 10:15 AM, Jan Hubicka wrote: >> >> Hello, >>> >>> diff --git a/gcc/hash-table.h b/gcc/hash-table.h >>> index 0f7e21a..443d16c 100644 >>> --- a/gcc/hash-table.h >>> +++ b/gcc/hash-table.h >>> @@ -803,7 +803,10

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-29 Thread Martin Sebor
On 06/29/2017 04:34 PM, Jan Hubicka wrote: The warning in the original code could have been suppressed (by casting the pointer to char*), but it was valid so I opted not to. I'd expect it to be possible to work around the bug but I don't have easy access to GCC 4.2 to reproduce it or verify

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-29 Thread Jan Hubicka
> > The warning in the original code could have been suppressed (by > casting the pointer to char*), but it was valid so I opted not > to. I'd expect it to be possible to work around the bug but > I don't have easy access to GCC 4.2 to reproduce it or verify > the fix. > > FWIW, after looking

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-29 Thread Martin Sebor
On 06/29/2017 10:15 AM, Jan Hubicka wrote: Hello, diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 0f7e21a..443d16c 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -803,7 +803,10 @@ hash_table::empty_slow () m_size_prime_index = nindex; } else

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-29 Thread Jan Hubicka
Hello, > diff --git a/gcc/hash-table.h b/gcc/hash-table.h > index 0f7e21a..443d16c 100644 > --- a/gcc/hash-table.h > +++ b/gcc/hash-table.h > @@ -803,7 +803,10 @@ hash_table::empty_slow () >m_size_prime_index = nindex; > } >else > -memset (entries, 0,

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-16 Thread Richard Biener
On Fri, Jun 16, 2017 at 9:38 AM, Richard Biener wrote: > On Thu, Jun 15, 2017 at 11:31 PM, Jason Merrill wrote: >> On Thu, Jun 15, 2017 at 12:26 PM, Martin Sebor wrote: >>> On 06/12/2017 03:36 PM, Jason Merrill wrote: On

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-16 Thread Richard Biener
On Thu, Jun 15, 2017 at 11:31 PM, Jason Merrill wrote: > On Thu, Jun 15, 2017 at 12:26 PM, Martin Sebor wrote: >> On 06/12/2017 03:36 PM, Jason Merrill wrote: >>> >>> On 06/08/2017 01:25 PM, Martin Sebor wrote: + if (TREE_CHAIN (DECL_ARGUMENTS

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-15 Thread Jason Merrill
On Thu, Jun 15, 2017 at 12:26 PM, Martin Sebor wrote: > On 06/12/2017 03:36 PM, Jason Merrill wrote: >> >> On 06/08/2017 01:25 PM, Martin Sebor wrote: >>> >>> + if (TREE_CHAIN (DECL_ARGUMENTS (f))) >>> +{ >>> + /* Skip constructors that aren't copy or move ctors.

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-15 Thread Martin Sebor
On 06/12/2017 03:36 PM, Jason Merrill wrote: On 06/08/2017 01:25 PM, Martin Sebor wrote: + if (TREE_CHAIN (DECL_ARGUMENTS (f))) +{ + /* Skip constructors that aren't copy or move ctors. */ + if (!copy_fn_p (f)) +continue; + + cpy_or_move_ctor_p = true; +} +

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-12 Thread Jason Merrill
On 06/08/2017 01:25 PM, Martin Sebor wrote: + if (TREE_CHAIN (DECL_ARGUMENTS (f))) + { + /* Skip constructors that aren't copy or move ctors. */ + if (!copy_fn_p (f)) + continue; + + cpy_or_move_ctor_p = true; + } + else + { +

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-08 Thread Martin Sebor
On 06/07/2017 07:09 PM, Jason Merrill wrote: On 06/06/2017 03:24 PM, Martin Sebor wrote: + /* Iterate over copy and move assignment overloads. */ + + for (ovl_iterator oi (fns); oi; ++oi) +{ + tree f = *oi; + + bool accessible = !access || !(TREE_PRIVATE (f) || TREE_PROTECTED

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-07 Thread Jason Merrill
On 06/06/2017 03:24 PM, Martin Sebor wrote: + /* Iterate over copy and move assignment overloads. */ + + for (ovl_iterator oi (fns); oi; ++oi) +{ + tree f = *oi; + + bool accessible = !access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f)); + + /* Skip template assignment

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-06 Thread Martin Sebor
On 06/05/2017 07:53 PM, Martin Sebor wrote: On 06/05/2017 01:13 PM, Martin Sebor wrote: On 06/05/2017 10:07 AM, Martin Sebor wrote: Maybe I should use a different approach and instead of trying to see if a function is deleted use trivially_xible to see if it's usable. That will mean changing

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-05 Thread Martin Sebor
On 06/05/2017 01:13 PM, Martin Sebor wrote: On 06/05/2017 10:07 AM, Martin Sebor wrote: Maybe I should use a different approach and instead of trying to see if a function is deleted use trivially_xible to see if it's usable. That will mean changing the diagnostics from "with a deleted special

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-05 Thread Martin Sebor
On 06/05/2017 10:07 AM, Martin Sebor wrote: Maybe I should use a different approach and instead of trying to see if a function is deleted use trivially_xible to see if it's usable. That will mean changing the diagnostics from "with a deleted special function" to "without trivial special

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-05 Thread Martin Sebor
Maybe I should use a different approach and instead of trying to see if a function is deleted use trivially_xible to see if it's usable. That will mean changing the diagnostics from "with a deleted special function" to "without trivial special function" but it will avoid calling

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-05 Thread Jason Merrill
On 06/04/2017 10:01 PM, Jason Merrill wrote: On 06/02/2017 05:28 PM, Martin Sebor wrote: On 05/31/2017 05:34 PM, Jason Merrill wrote: On 05/27/2017 06:44 PM, Martin Sebor wrote: + /* True if the class is trivial and has a trivial non-deleted copy + assignment, copy ctor, and default

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-04 Thread Jason Merrill
On 06/02/2017 05:28 PM, Martin Sebor wrote: On 05/31/2017 05:34 PM, Jason Merrill wrote: On 05/27/2017 06:44 PM, Martin Sebor wrote: + /* True if the class is trivial and has a trivial non-deleted copy + assignment, copy ctor, and default ctor, respectively. The last + one isn't used

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-06-02 Thread Martin Sebor
On 05/31/2017 05:34 PM, Jason Merrill wrote: On 05/27/2017 06:44 PM, Martin Sebor wrote: + /* True if the class is trivial and has a trivial non-deleted copy + assignment, copy ctor, and default ctor, respectively. The last + one isn't used to issue warnings but only to decide what

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-31 Thread Jason Merrill
On 05/27/2017 06:44 PM, Martin Sebor wrote: + /* True if the class is trivial and has a trivial non-deleted copy + assignment, copy ctor, and default ctor, respectively. The last + one isn't used to issue warnings but only to decide what suitable + alternatives to offer as

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-27 Thread Martin Sebor
+/* Return true if class TYPE meets a relaxed definition of standard-layout. + In particular, the requirement that it "has all non-static data members + nd bit-fields in the class and its base classes first declared in the + same class" is not considered. */ + +static bool

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-24 Thread Jason Merrill
On 05/24/2017 04:28 PM, Martin Sebor wrote: Attached is an updated patch with the requested changes. I've also renamed the option -Wclass-memaccess to avoid suggesting that the warning focuses solely on non-trivial types, and updated its wording and comments throughout to refer to value

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-24 Thread Martin Sebor
Attached is an updated patch with the requested changes. I've also renamed the option -Wclass-memaccess to avoid suggesting that the warning focuses solely on non-trivial types, and updated its wording and comments throughout to refer to value initialization rather than default initialization.

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-24 Thread Martin Sebor
On 05/21/2017 10:50 PM, Jason Merrill wrote: On Sun, May 21, 2017 at 7:59 PM, Martin Sebor wrote: On 05/19/2017 03:42 PM, Jason Merrill wrote: On Fri, May 19, 2017 at 4:07 PM, Martin Sebor wrote: On 05/19/2017 01:07 PM, Jason Merrill wrote: On Tue, May

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-21 Thread Jason Merrill
On Sun, May 21, 2017 at 7:59 PM, Martin Sebor wrote: > On 05/19/2017 03:42 PM, Jason Merrill wrote: >> On Fri, May 19, 2017 at 4:07 PM, Martin Sebor wrote: >>> On 05/19/2017 01:07 PM, Jason Merrill wrote: On Tue, May 16, 2017 at 5:39 PM, Martin Sebor

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-21 Thread Martin Sebor
On 05/19/2017 03:42 PM, Jason Merrill wrote: On Fri, May 19, 2017 at 4:07 PM, Martin Sebor wrote: On 05/19/2017 01:07 PM, Jason Merrill wrote: On Tue, May 16, 2017 at 5:39 PM, Martin Sebor wrote: On 05/16/2017 01:41 PM, Jason Merrill wrote: I'm still

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-19 Thread Jason Merrill
On Fri, May 19, 2017 at 4:07 PM, Martin Sebor wrote: > On 05/19/2017 01:07 PM, Jason Merrill wrote: >> >> On Tue, May 16, 2017 at 5:39 PM, Martin Sebor wrote: >>> >>> On 05/16/2017 01:41 PM, Jason Merrill wrote: >>> I'm still not convinced we need to

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-19 Thread Martin Sebor
On 05/19/2017 01:07 PM, Jason Merrill wrote: On Tue, May 16, 2017 at 5:39 PM, Martin Sebor wrote: On 05/16/2017 01:41 PM, Jason Merrill wrote: I'm still not convinced we need to consider standard-layout at all. I agree. The patch doesn't make use of

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-19 Thread Jason Merrill
On Tue, May 16, 2017 at 5:39 PM, Martin Sebor wrote: > On 05/16/2017 01:41 PM, Jason Merrill wrote: > >> I'm still not convinced we need to consider standard-layout at all. > > I agree. The patch doesn't make use of is_standard_layout_p(). > It defines its own helper called

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-17 Thread Pedro Alves
[Meant to add this to the other email, but forgot to copy it back.] On 05/12/2017 03:31 AM, Martin Sebor wrote: > + // Zeroing out is diagnosed only because it's difficult not to. > + // Otherwise, a class that's non-trivial only because it has > + // a non-trivial dtor can be safely zeroed

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-17 Thread Pedro Alves
On 05/17/2017 02:55 AM, Martin Sebor wrote: > On 05/16/2017 04:48 PM, Pedro Alves wrote: >> On 05/16/2017 08:41 PM, Jason Merrill wrote: >> >>> I agree that it makes sense to >>> check for a trivial assignment operator specifically. I guess we want >>> a slightly stronger "trivially copyable"

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-16 Thread Martin Sebor
On 05/16/2017 04:48 PM, Pedro Alves wrote: On 05/16/2017 08:41 PM, Jason Merrill wrote: I agree that it makes sense to check for a trivial assignment operator specifically. I guess we want a slightly stronger "trivially copyable" that also requires a non-deleted assignment operator. It seems

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-16 Thread Pedro Alves
On 05/16/2017 08:41 PM, Jason Merrill wrote: > I agree that it makes sense to > check for a trivial assignment operator specifically. I guess we want > a slightly stronger "trivially copyable" that also requires a > non-deleted assignment operator. > > It seems to me that the relevant tests

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-16 Thread Martin Sebor
On 05/16/2017 01:41 PM, Jason Merrill wrote: On Thu, May 11, 2017 at 12:23 PM, Martin Sebor wrote: The challenge with using memcpy or memset with class types is figuring out if it's being called to copy-construct a new object or assign a new value to an existing one. In

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-16 Thread Jason Merrill
On Thu, May 11, 2017 at 12:23 PM, Martin Sebor wrote: > The challenge with using memcpy or memset with class types is > figuring out if it's being called to copy-construct a new object > or assign a new value to an existing one. In general it's not > possible to tell so the

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-11 Thread Martin Sebor
I found a few more instances of the warning and a couple of bugs in the fixes for it. The attached update corrects those as well. On 05/11/2017 02:01 PM, Martin Sebor wrote: Attached is revision 2 of the patch that addresses of the feedback I got from Pedro (thanks again). As I explained in

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-11 Thread Martin Sebor
Attached is revision 2 of the patch that addresses of the feedback I got from Pedro (thanks again). As I explained in my response (https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00925.html) it's not entirely practical to rely on the strict interpretation of the C++ definition of type triviality

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-11 Thread Martin Sebor
On 05/11/2017 10:34 AM, Jakub Jelinek wrote: On Thu, May 11, 2017 at 10:23:48AM -0600, Martin Sebor wrote: Unlike in C, the preferred way to initialize objects in C++ is to use some form of initialization (as opposed to memset). The preferred way to copy objects is using the copy ctor or

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-11 Thread Jakub Jelinek
On Thu, May 11, 2017 at 10:23:48AM -0600, Martin Sebor wrote: > Unlike in C, the preferred way to initialize objects in C++ > is to use some form of initialization (as opposed to memset). > The preferred way to copy objects is using the copy ctor or > assignment operator (as opposed to memcpy).

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-11 Thread Martin Sebor
On 04/30/2017 02:02 PM, Pedro Alves wrote: Hi Martin, Thanks much for doing this. A few comments below, in light of my experience doing the equivalent checks in the gdb patch linked below, using standard C++11. Thanks for the feedback! It gave me quite a bit to think about. The challenge

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-03 Thread Martin Sebor
On 04/30/2017 05:39 PM, Joseph Myers wrote: On Sat, 29 Apr 2017, Martin Sebor wrote: +The safe way to either initialize or "reset" objects of non-trivial Should use TeX quotes in Texinfo files, ``reset''. Heh :) I wrestled with Emacs to get rid of those, It kept replacing my plain quotes

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-01 Thread Jason Merrill
Pedro's suggestions all sound good to me. Jason

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-04-30 Thread Joseph Myers
On Sat, 29 Apr 2017, Martin Sebor wrote: > +The safe way to either initialize or "reset" objects of non-trivial Should use TeX quotes in Texinfo files, ``reset''. -- Joseph S. Myers jos...@codesourcery.com

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-04-30 Thread Pedro Alves
Hi Martin, Thanks much for doing this. A few comments below, in light of my experience doing the equivalent checks in the gdb patch linked below, using standard C++11. On 04/29/2017 09:09 PM, Martin Sebor wrote: > Calling memset, memcpy, or similar to write to an object of > a non-trivial type