From patchwork Mon Apr 12 22:59:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11892 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 6ADADBD1F6 for ; Mon, 12 Apr 2021 23:00:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 244BF687EC; Tue, 13 Apr 2021 01:00:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fHub573R"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A4A7605AE for ; Tue, 13 Apr 2021 01:00:42 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A1F746F2 for ; Tue, 13 Apr 2021 01:00:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618268440; bh=M86+T0Hyl2XeTFZPHn4XfxWMmYK5uDykONM7Gw1nOao=; h=From:To:Subject:Date:From; b=fHub573R/EEXd2M+DZPY+ZnOuI9vMLs8l5z7frzPajuGHpdanJqOSFqNcmNSA1adB FIQb66ITzhVkCymgWouREYwBbWTiv3LQhOt17zrsyiaxmXoW4Nyj8hquWyLohWthgu ePwjcZynoPSS7VsmiPIXvYV9PT/BHAE9oqkMEY6Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 01:59:48 +0300 Message-Id: <20210412225948.13796-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH/RFC] libcamera: bound_method: Please gcc undefined behaviour sanitizer 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Enabling the gcc undefined behaviour sanitizer (with the meson configure -Db_sanitize=undefined option) causes many tests to fail, with errors such as the following (for test/object-invoke): ../../include/libcamera/bound_method.h:198:27: runtime error: member access within address 0x55fcd7bfbd38 which does not point to an object of type 'BoundMethodBase' 0x55fcd7bfbd38: note: object has invalid vptr fc 55 00 00 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 00 00 00 00 00 00 00 4b c6 72 88 ^~~~~~~~~~~~~~~~~~~~~~~ invalid vptr ../../include/libcamera/bound_method.h:198:41: runtime error: member call on null pointer of type 'struct InvokedObject' ../../include/libcamera/bound_method.h:198:41: runtime error: member access within null pointer of type 'struct InvokedObject' Segmentation fault The root cause isn't clear, but this change fixes the issue. It may be a bug in gcc. Signed-off-by: Laurent Pinchart Acked-by: Kieran Bingham --- include/libcamera/bound_method.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) If anyone is interested in trying the gcc undefined behaviour sanitizer, this patch is needed. Bonus points if you can spot why it helps. diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index f216e3b56826..de17fdee3612 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -163,7 +163,8 @@ public: R invoke(Args... args) override { - return (static_cast(this->obj_)->*func_)(args...); + T *obj = static_cast(this->obj_); + return (obj->*func_)(args...); } private: @@ -195,7 +196,8 @@ public: void invoke(Args... args) override { - (static_cast(this->obj_)->*func_)(args...); + T *obj = static_cast(this->obj_); + (obj->*func_)(args...); } private: