Mesa (master): nir/opt_copy_prop_vars: Quiet valgrind warning about overlapping memcpy.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 22:37:31 UTC 2020


Module: Mesa
Branch: master
Commit: a82f664d0a4968cfc123be03e1608f430a99231b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a82f664d0a4968cfc123be03e1608f430a99231b

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug  4 16:15:04 2020 -0700

nir/opt_copy_prop_vars: Quiet valgrind warning about overlapping memcpy.

The warning is kind of silly:

Test case 'dEQP-GLES2.functional.shaders.indexing.tmp_array.vec3_const_write_static_read_vertex'..
==1874780== Source and destination overlap in memcpy(0xa261690, 0xa261690, 160)
==1874780==    at 0x484D498: __GI_memcpy (vg_replace_strmem.c:1037)
==1874780==    by 0x596FC07: copy_entry_remove (nir_opt_copy_prop_vars.c:296)

The "memcpy is undefined if they overlap" thing is surely meant to be
"memcpy with *partial* overlap is undefined", but let's keep anyone else
from having to debug this.

Reviewed-by: Rob Clark <robdclark at chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6178>

---

 src/compiler/nir/nir_opt_copy_prop_vars.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/compiler/nir/nir_opt_copy_prop_vars.c b/src/compiler/nir/nir_opt_copy_prop_vars.c
index fddbf88daf9..8b41e0e8832 100644
--- a/src/compiler/nir/nir_opt_copy_prop_vars.c
+++ b/src/compiler/nir/nir_opt_copy_prop_vars.c
@@ -290,10 +290,10 @@ static void
 copy_entry_remove(struct util_dynarray *copies,
                   struct copy_entry *entry)
 {
-   /* This also works when removing the last element since pop don't shrink
-    * the memory used by the array, so the swap is useless but not invalid.
-    */
-   *entry = util_dynarray_pop(copies, struct copy_entry);
+   const struct copy_entry *src =
+      util_dynarray_pop_ptr(copies, struct copy_entry);
+   if (src != entry)
+      *entry = *src;
 }
 
 static bool



More information about the mesa-commit mailing list