[{"id":22823,"web_url":"https://patchwork.libcamera.org/comment/22823/","msgid":"<165157466076.1217485.226640814865320093@Monstersaurus>","date":"2022-05-03T10:44:20","subject":"Re: [libcamera-devel] [PATCH] libcamera: object: Silence gcc false\n\tpositive error in release mode","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nQuoting Laurent Pinchart via libcamera-devel (2022-04-29 22:58:41)\n> gcc 10 and 11 produce an error when compiling libcamera in release mode:\n> \n> In file included from ../../src/libcamera/base/object.cpp:13:\n> ../../include/libcamera/base/message.h: In member function ‘void libcamera::Object::notifyThreadMove()’:\n> ../../include/libcamera/base/message.h:58:47: error: array subscript ‘const libcamera::InvokeMessage[0]’ is partly outside array bounds of ‘libcamera::Message [1]’ [-Werror=array-bounds]\n>    58 |         Semaphore *semaphore() const { return semaphore_; }\n>       |                                               ^~~~~~~~~~\n> ../../src/libcamera/base/object.cpp:280:17: note: while referencing ‘msg’\n>   280 |         Message msg(Message::ThreadMoveMessage);\n>       |                 ^~~\n> \n> This seems to be a false positive, given that msg->type() can never be\n> equal to Message::InvokeMessage in Object::message() when called from\n> Object::notifyThreadMove(), as the message is created there with the\n> Message::ThreadMoveMessage type. The problem as been reported in\n> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105400, but the error\n> nonetheless needs to be fixed without waiting for a new gcc release, and\n> a dynamic_cast does the job with a small additional runtime cost that\n> shouldn't be a big issue, given that moving objects between threads is a\n> rare operation.\n\nAgreed, I think we should just merge this as a suitable solution.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Bug: https://bugs.libcamera.org/show_bug.cgi?id=125\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/base/object.cpp | 6 +++++-\n>  1 file changed, 5 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp\n> index ec5b55d125d1..92cecd22fbe9 100644\n> --- a/src/libcamera/base/object.cpp\n> +++ b/src/libcamera/base/object.cpp\n> @@ -189,7 +189,11 @@ void Object::message(Message *msg)\n>  {\n>         switch (msg->type()) {\n>         case Message::InvokeMessage: {\n> -               InvokeMessage *iMsg = static_cast<InvokeMessage *>(msg);\n> +               /*\n> +                * A static_cast should be enough, but gcc 10 and 11 choke on\n> +                * it in release mode (with -O2 or -O3).\n> +                */\n> +               InvokeMessage *iMsg = dynamic_cast<InvokeMessage *>(msg);\n>                 Semaphore *semaphore = iMsg->semaphore();\n>                 iMsg->invoke();\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 72A08C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  3 May 2022 10:44:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CCE2A65644;\n\tTue,  3 May 2022 12:44:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 556A76563D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  3 May 2022 12:44:24 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D97C5E5;\n\tTue,  3 May 2022 12:44:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651574665;\n\tbh=yy+xJ+LrqlAHoq5b802vYUELWJQrfMjxqSr3kK7x9z0=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=YUArsIl2NqJL4OO/6iJukazlq3l0bP93xD7jwBEB3Gg4dsISgwK5g/PJfA9ri8oWM\n\tRv1PUtEFsgUjvhLKQrVztgBEAgnXpMA1oD3MGoMAvEDgeLl8qc+JSVUR+eXwVRiQMD\n\ta06G9x8RYvgZT5eo8f7lcBvJZRmEQl5MDHRKcWZSJdLAANQa/lRC0i7AMdMjQ0VasW\n\t7Cr9VVpw8iPf0YSJzgEFFy/ildwChi9VGqAp+DBKr7Ex5/ey19THw7vO3Q0MB5VRBn\n\tOx7V2Dx7YCjhaeSF6MEZ8JIIkLozetFf+RlqQHezCXKfQgR2QK5Q+eQrv9Fbwi7FuU\n\tp0tw5cAEP9lMA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651574663;\n\tbh=yy+xJ+LrqlAHoq5b802vYUELWJQrfMjxqSr3kK7x9z0=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=j6y3Evb3a0e97xVu50Zzj8HAcojVl4xRfRzgWGNXtXKPWw1Dd0SeV3t3wX3dE9Zh6\n\tAbbzvbQnuuoIzU9/1gnFE+UAUh78sVSekvM93d5RPFoSEWkx77p1qkZqyZA33UNHRQ\n\tusGgtix/3PWmORVgzNHnZuRvTGm/Y4F29dxnt5U0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"j6y3Evb3\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220429215841.19913-1-laurent.pinchart@ideasonboard.com>","References":"<20220429215841.19913-1-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 03 May 2022 11:44:20 +0100","Message-ID":"<165157466076.1217485.226640814865320093@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] libcamera: object: Silence gcc false\n\tpositive error in release mode","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]