This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Jan Hubicka <hubicka at ucw dot cz>, Jason Merrill <jason at redhat dot com>, Pedro Alves <palves at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 30 Jun 2017 00:34:09 +0200
- Subject: Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)
- Authentication-results: sourceware.org; auth=none
- References: <b729a519-fdef-1ad7-3e33-4b3d451d1a1a@gmail.com> <656ca1db-1082-b1ed-a911-ba7bf48f09c0@redhat.com> <CADzB+2=5ZD4YkENJ65bn-Q-d1RXgn3nGKoFQE+pgja_KPNO1xw@mail.gmail.com> <eb698a52-b142-bec1-e91e-9e85bc2bfa7f@gmail.com> <20170629161506.GA25586@atrey.karlin.mff.cuni.cz> <f43bf7aa-3f57-1b08-8ed2-96cbef51e89f@gmail.com>
>
> 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 at the function again, I wondered if zeroing
> out the elements (either way) was the right thing to do and if
> they shouldn't be cleared by calling Descriptor::mark_empty()
> instead, like in alloc_entries(), but making that change broke
> a bunch of ipa/ipa-pta-*.c tests. It's not really clear to me
> what this code is supposed to do.
Well, it is a standard hash table. The problem I hit was
lookup_with_hash walking infinitly around the hash table because
all elements seemed used.
is_empty is defined as:
template <typename Type>
inline bool
pointer_hash <Type>::is_empty (Type *e)
{
return e == NULL;
}
and mark_empty as
template <typename Type>
inline void
pointer_hash <Type>::mark_empty (Type *&e)
{
e = NULL;
}
I guess they are supposed to be definable to other implementations
but then the former memset code would break.
> Martin
>
> PS Does this help at all?
>
> @@ -804,8 +804,8 @@ hash_table<Descriptor, Allocator>::empty_slow ()
> }
> else
> {
> - for ( ; size; ++entries, --size)
> - *entries = value_type ();
> + for (size_t i = 0; i != size; ++i)
> + entries[i] = value_type ();
I can give it a try tomorrow. Still wonder what goes wrong with ctors with 4.2 (and 4.3 as well apparently)
Honza
> }
> m_n_deleted = 0;
> m_n_elements = 0;