From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id 334D9383FF6E for ; Sun, 11 Dec 2022 19:53:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 334D9383FF6E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id 68D9C10049360 for ; Sun, 11 Dec 2022 19:53:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 4SOLpWlfp3A764SOLpOKfY; Sun, 11 Dec 2022 19:53:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=X/uXlEfe c=1 sm=1 tr=0 ts=63963545 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=sHyYjHe8cH0A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=SkpvdfB15P7HYdhvLskA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=S4V1/sFk8vGyhFiSoJ9RIX01uAYJya9m2S0tU4XSQuY=; b=KhU00RPeK9/bGw8Pp/CwDxALAX Cg9x/aWEfcV6B1ZFP0Gko/pa/tmwKcz1HNouE6PJmQytTX1W8gpcKguge5KLhVbt6KmH7oxZnNuUI Tgq1auXRGR05TGzvYCoZ2w9cP; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:51026 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p4SOL-003abE-27; Sun, 11 Dec 2022 12:53:41 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix crash in is_nocall_function Date: Sun, 11 Dec 2022 12:53:31 -0700 Message-Id: <20221211195331.252485-1-tom@tromey.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.76.186 X-Source-L: No X-Exim-ID: 1p4SOL-003abE-27 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:51026 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3028.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: is_nocall_function anticipates only being called for a function or a method. However, PR gdb/29871 points out a situation where an unusual expression -- but one that parses to a valid, if extremely weird, function call -- breaks this assumption. This patch changes is_nocall_function to remove this assert and instead simply return 'false' in this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29871 --- gdb/gdbtypes.c | 4 ++-- gdb/gdbtypes.h | 4 +--- gdb/testsuite/gdb.base/exprs.exp | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 2166257f71e..30dd7744553 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4037,8 +4037,8 @@ type_byte_order (const struct type *type) bool is_nocall_function (const struct type *type) { - gdb_assert (type->code () == TYPE_CODE_FUNC - || type->code () == TYPE_CODE_METHOD); + if (type->code () != TYPE_CODE_FUNC && type->code () != TYPE_CODE_METHOD) + return false; return TYPE_CALLING_CONVENTION (type) == DW_CC_nocall; } diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index d7189ff9813..8fc5c97c95a 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2845,9 +2845,7 @@ extern unsigned int overload_debug; to call by the debugger. This usually indicates that the function does not follow the target's - standard calling convention. - - The TYPE argument must be of code TYPE_CODE_FUNC or TYPE_CODE_METHOD. */ + standard calling convention. */ extern bool is_nocall_function (const struct type *type); diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index 5bf03bf1320..b8698880339 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -271,3 +271,7 @@ gdb_test "print & (void) v_char" "value not located in memory." # Regression test for "&&". gdb_test "print null_t_struct && null_t_struct->v_int_member == 0" \ " = 0" + +# Regression test for unusual function-call parse that caused a crash. +gdb_test "print v_short++ (97)" \ + "cast the call to its declared return type" -- 2.38.1