From patchwork Fri Apr 29 21:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15760 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ECFCFC0F2A for ; Fri, 29 Apr 2022 21:58:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 645FB604A5; Fri, 29 Apr 2022 23:58:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651269528; bh=GKHBiSpE2wKUZicem31Wt7sxwNvoiLjnHze2MZV7JbE=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nPBtXWG8rY3lzbR1V7TO86FcIR+maKntDx541onb1Ma0RxXRKp9EcKaX/ofBkv3m+ ugLv3HGH+U0jW/bdt2MK801kjzMl0rZDnveNDlgs5jJTBATohRoTWe/5GOi3fP0UU4 NDphaDV5joHLP4Ths+zk+aixav+vZG7TagF0k+HrIBWlJL2Ty28eIFV2Rv9KHvrnCm L6n6vsjVjF3VqSwPDkJjMfyJu7aVNkOeu75AfoWrxTjtbe7O4GS3E1CblFCV+fbPhg r+wKXumhx3ZTRper+I6Qge7q7+qce73Hh1tagqXKtscQb5SD84B4CsE32SB1l7JqjM fVVJ3PZYqcYmQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 130B46042F for ; Fri, 29 Apr 2022 23:58:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="p4IjbRuu"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 820FE45F for ; Fri, 29 Apr 2022 23:58:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651269525; bh=GKHBiSpE2wKUZicem31Wt7sxwNvoiLjnHze2MZV7JbE=; h=From:To:Subject:Date:From; b=p4IjbRuukbLd07iB9Zs/uw6p/hkRlD1uKzEU6I47G9GotktSmn2CeoZscgn5EdiJE Eg3Oi3jTT8vG5mm4Llpz0ALpLlsJtCF9K3Puvtf70jMnbnBW7YIfchInSY97U6a50F 8SJ01sPZS4BEwFPvZOaai27iPmNLv9fCiQubsmAQ= To: libcamera-devel@lists.libcamera.org Date: Sat, 30 Apr 2022 00:58:41 +0300 Message-Id: <20220429215841.19913-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: object: Silence gcc false positive error in release mode X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" gcc 10 and 11 produce an error when compiling libcamera in release mode: In file included from ../../src/libcamera/base/object.cpp:13: ../../include/libcamera/base/message.h: In member function ‘void libcamera::Object::notifyThreadMove()’: ../../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] 58 | Semaphore *semaphore() const { return semaphore_; } | ^~~~~~~~~~ ../../src/libcamera/base/object.cpp:280:17: note: while referencing ‘msg’ 280 | Message msg(Message::ThreadMoveMessage); | ^~~ This seems to be a false positive, given that msg->type() can never be equal to Message::InvokeMessage in Object::message() when called from Object::notifyThreadMove(), as the message is created there with the Message::ThreadMoveMessage type. The problem as been reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105400, but the error nonetheless needs to be fixed without waiting for a new gcc release, and a dynamic_cast does the job with a small additional runtime cost that shouldn't be a big issue, given that moving objects between threads is a rare operation. Bug: https://bugs.libcamera.org/show_bug.cgi?id=125 Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/base/object.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp index ec5b55d125d1..92cecd22fbe9 100644 --- a/src/libcamera/base/object.cpp +++ b/src/libcamera/base/object.cpp @@ -189,7 +189,11 @@ void Object::message(Message *msg) { switch (msg->type()) { case Message::InvokeMessage: { - InvokeMessage *iMsg = static_cast(msg); + /* + * A static_cast should be enough, but gcc 10 and 11 choke on + * it in release mode (with -O2 or -O3). + */ + InvokeMessage *iMsg = dynamic_cast(msg); Semaphore *semaphore = iMsg->semaphore(); iMsg->invoke();