From: René Scharfe Date: Thu, 14 Nov 2019 16:41:21 GMT Subject: Re: coccinelle: adjustments for array.cocci? Message-ID: <53346d52-e096-c651-f70a-ce6ca4d82ff9@web.de> In-Reply-To: Am 14.11.19 um 14:15 schrieb Markus Elfring: > You mentioned “failures”. - I became curious then if corresponding software > development challenges can be clarified a bit more. Let's try to restore/repeat the pertinent paragraph, with context and attribution: Am 13.11.19 um 03:11 schrieb Junio C Hamano: > René Scharfe writes: >> Am 12.11.19 um 16:08 schrieb Markus Elfring: >>> >>> Do you find the following code variant (for the semantic patch language) also useful? >>> >>> memcpy( >>> ( ptr, E, n * >>> - sizeof(*(ptr)) >>> + sizeof(T) >>> | arr, E, n * >>> - sizeof(*(arr)) >>> + sizeof(T) >>> | E, ptr, n * >>> - sizeof(*(ptr)) >>> + sizeof(T) >>> | E, arr, n * >>> - sizeof(*(arr)) >>> + sizeof(T) >>> ) >>> ) > >> This reduces duplication in the semantic patch, which is nice. I think >> I tried something like that at the time, but found that it failed to >> produce some of the cases in 921d49be86 ("use COPY_ARRAY for copying >> arrays", 2019-06-15) for some reason. > Thanks for mentioning. > > I too recall that seemingly redundant entries were noticed during > the review and at least back then removing the seemingly redundant > ones caused failures in rewriting. You can see for yourself by: 1. applying the patch at the bottom to implement your suggested change, 2. running "git show 921d49be86 | patch -p1 -R" to undo 921d49be86, 3. running "make contrib/coccinelle/array.cocci.patch", 4. running "patch -p1 8 -- diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci index 46b8d2ee11..e7bcbefcc1 100644 --- a/contrib/coccinelle/array.cocci +++ b/contrib/coccinelle/array.cocci @@ -12,27 +12,25 @@ T *ptr; T[] arr; expression E, n; @@ + memcpy( ( - memcpy(ptr, E, -- n * sizeof(*(ptr)) -+ n * sizeof(T) - ) + ptr, E, n * +- sizeof(*(ptr)) ++ sizeof(T) | - memcpy(arr, E, -- n * sizeof(*(arr)) -+ n * sizeof(T) - ) + arr, E, n * +- sizeof(*(arr)) ++ sizeof(T) | - memcpy(E, ptr, -- n * sizeof(*(ptr)) -+ n * sizeof(T) - ) + E, ptr, n * +- sizeof(*(ptr)) ++ sizeof(T) | - memcpy(E, arr, -- n * sizeof(*(arr)) -+ n * sizeof(T) - ) + E, arr, n * +- sizeof(*(arr)) ++ sizeof(T) ) + ) @@ type T;