On 9 Sep 2023, at 10:48, James Raphael Tiovalen wrote:
> C++ does not allow implicit conversion from void pointer to a specific
> pointer type. This change removes the cast from uint32_t* to void* in
> `hash_words_32aligned` and adds an explicit typecast from uint32_t* to
> uint64_t* in `hash_words_inline`.
>
> This issue was initially discovered on G++ v9.2.0 when a downstream C++
> application included the hash.h header file and was compiled on an AMD
> Ryzen Zen 2 CPU (__SSE4_2__ && __x86_64__). On the latest G++ version,
> it would throw an error. On the latest GCC version with `-Wc++-compat`,
> it would throw a warning.
>
> Acked-by: Mike Pattrick <m...@redhat.com>
> Signed-off-by: James Raphael Tiovalen <jamestio...@gmail.com>
> ---
> Revisions:
>
> v1 -> v2: Fix build issue due to `-Wcast-align=strict` warning.
> v2 -> v3: Fix `-Warray-bounds=1` warning.
> v3 -> v4: Use `ALIGNED_CAST` as per Ilya's suggestion.
> ---
> lib/hash.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/hash.h b/lib/hash.h
> index 7b7f70c11..27ad782ea 100644
> --- a/lib/hash.h
> +++ b/lib/hash.h
> @@ -200,7 +200,7 @@ hash_finish32(uint64_t hash, uint32_t final, uint32_t
> semifinal)
> static inline uint32_t
> hash_words_32aligned(const uint32_t *p_, size_t n_words, uint32_t basis)
> {
> - const uint32_t *p = (const void *) p_;
> + const uint32_t *p = p_;
If the casting is no longer needed, we might as well rename the input parameter
from p_ to p and we might be done.
Including Mike in this conversation as he did the original implementation, so
it would be good to understand his intention.
> uint32_t hash1 = basis;
> uint32_t hash2 = 0;
> uint32_t hash3 = n_words;
> @@ -254,7 +254,7 @@ hash_words_32aligned(const uint32_t *p_, size_t n_words,
> uint32_t basis)
> static inline uint32_t
> hash_words_inline(const uint32_t *p_, size_t n_words, uint32_t basis)
> {
> - const uint64_t *p = (const void *)p_;
> + const uint64_t *p = ALIGNED_CAST(const uint64_t *, p_);
^^
One space to many.
> uint64_t hash1 = basis;
> uint64_t hash2 = 0;
> uint64_t hash3 = n_words;
> --
> 2.42.0
>
> _______________________________________________
> dev mailing list
> d...@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev