From 490b06e24bbfa4cd4cdbeaa82ef15ed48694841e Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Tue, 25 Jun 2019 12:17:58 +0200 Subject: [PATCH] queue: redefine TAILQ_REMOVE for scan-build scan-build can't follow double pointers in tailqs and often assumes that removed elements are still on the list, so now if we detect __clang_analyzer__ we'll redefine TAILQ_REMOVE with extra asserts to silence those scan-build errors. Change-Id: I14134d8e75f7829e178b74d19f711f77cf018f14 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459285 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Tomasz Zawadzki Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: yidong0635 --- include/spdk/queue.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/spdk/queue.h b/include/spdk/queue.h index a24dd0070..24e2e2e20 100644 --- a/include/spdk/queue.h +++ b/include/spdk/queue.h @@ -50,6 +50,28 @@ extern "C" { #include "spdk/queue_extras.h" #endif +/* + * scan-build can't follow double pointers in queues and often assumes + * that removed elements are still on the list. We redefine TAILQ_REMOVE + * with extra asserts to silence it. + */ +#ifdef __clang_analyzer__ +#undef TAILQ_REMOVE +#define TAILQ_REMOVE(head, elm, field) do { \ + __typeof__(elm) _elm; \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + /* make sure the removed elm is not on the list anymore */ \ + TAILQ_FOREACH(_elm, head, field) { \ + assert(_elm != elm); \ + } \ +} while (0) +#endif + #ifdef __cplusplus } #endif