From patchwork Wed Jul 17 11:19:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joel Hutton X-Patchwork-Id: 1133267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505200-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xURVQZsA"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="GX2SaVFi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="GX2SaVFi"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45pZYw311Lz9s7T for ; Wed, 17 Jul 2019 21:20:19 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=I5BotLWHa6TMf5DTw2j2bXYGE/O3UOMPlZvem0ydHL/7SmG1gi JnuNpuEjTgPEGLRE7DItrNI/Dk9HvSjSRh1CTDKgonDgeKlEow59IYJs4k1scBV5 NBnkD22fNr9wARW5SjrzNsP18razo681/0Oy25GXwZ39//c23hQQLL6J4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=zeBEsGqaALfL+eRYLbG+iSWgQII=; b=xURVQZsAEY5Y8x5PgFV5 8pFAXnbzQ/9zRVGrLtxe4GCPyweucSMyP8mBBK/GRN6FL8lcWt8doNdw3yUVaAUM pFYJSAFTIX+/WM9fijzuDUaSwXbKw8arfUJY17DEsC6oOUtuhxPxpDr0soEAxOoW xiPHYmus5MJ1ajuROXhYijk= Received: (qmail 55432 invoked by alias); 17 Jul 2019 11:20:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 55421 invoked by uid 89); 17 Jul 2019 11:20:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60077.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.77) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Jul 2019 11:20:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LDqYUE8Px+UTltIJTET3sdxMLlr0/QYGQ1J8LkL0D5k=; b=GX2SaVFiYiNd5V5AS0TJaljn2dEB8EF9EtLCc9QXblaEgeBU0vr186BjdY09ph6UldV+r8k+k0f9NxSg53SyuJ+vz6/nRwtfoHTw+GQ/nOro7pdskR0aEKSLSQ4qDpfOKq5D907c9LTz2dcK8+389OPyhA+Mqz4TrRIDxfnvgBo= Received: from VI1PR0802CA0019.eurprd08.prod.outlook.com (10.172.253.157) by DB6PR0802MB2599.eurprd08.prod.outlook.com (10.172.252.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Wed, 17 Jul 2019 11:20:04 +0000 Received: from VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::202) by VI1PR0802CA0019.outlook.office365.com (2603:10a6:800:aa::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2073.14 via Frontend Transport; Wed, 17 Jul 2019 11:20:04 +0000 Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT013.mail.protection.outlook.com (10.152.19.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2052.18 via Frontend Transport; Wed, 17 Jul 2019 11:20:03 +0000 Received: ("Tessian outbound 350ce6c32571:v24"); Wed, 17 Jul 2019 11:20:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2fd521cf946c5605 X-CR-MTA-TID: 64aa7808 Received: from 93e67883904d.1 (cr-mta-lb-1.cr-mta-net [104.47.13.57]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4BC1C8B9-ACEE-4151-8EE0-2DBE677FB479.1; Wed, 17 Jul 2019 11:19:58 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 93e67883904d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Wed, 17 Jul 2019 11:19:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bdv2uONSKkxkhFrCxygtH5irLCpTY6fCL0WF9gLQJo6Kbz3j7UsJXMApohqgDqAokPPqKErtNBorRm3S1wENOI2C+hm7ALA5GCPkV/Utcn4C5UPo5zj4iCqz7LNR2/KcXsdpvdmNNz+8/yUjQRNe6fa8uPoWXq4KPb0HC5GzILsJfW/JWqAt4sAF48DgOcmEzD+U4HUZqyT0XBISsvtX5y59+KDPe9pj7QR4SlnYojxy+gmd15mVavTevRPEh26hcmpU9lrvNpHUQyS6u672r6h1VEpf/NEu/OvhC7XTE4z7JrKZF90Gfdzx5sZkhhDHiqHnGKvgqH2FqP8r1KoYbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LDqYUE8Px+UTltIJTET3sdxMLlr0/QYGQ1J8LkL0D5k=; b=YYmRSIL+dQ0ksDk3I/vO0A+bR5WqWI3704lhWtNeYrlnYin8t8KIiexueXlcosiOdG60JLo/CW8hI4Iy+gBS9BF9mF/d2PlBRolkP5QGnZlhUEN+ZKxBqBI0DFEnr6EDJsjcwjmw7SkJoblgUpxaKCuvTsn1bPA31wsQicmxnA/ruwxJmD8SQe/oW1yjHQ3FozlpKSyojw9pxuLc9UMRcM9CLm0byG3e5qljpw2ZpmEPga4V/4OkbWFKVYMuj4WocEFlbcUt7chhPPhIJr0NZhFKr/hLfF7c/l3zCpRs/hFPt+YmNR3SmbWY8BKPrYlBciLypTxvFpJYD2xZtdbcQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LDqYUE8Px+UTltIJTET3sdxMLlr0/QYGQ1J8LkL0D5k=; b=GX2SaVFiYiNd5V5AS0TJaljn2dEB8EF9EtLCc9QXblaEgeBU0vr186BjdY09ph6UldV+r8k+k0f9NxSg53SyuJ+vz6/nRwtfoHTw+GQ/nOro7pdskR0aEKSLSQ4qDpfOKq5D907c9LTz2dcK8+389OPyhA+Mqz4TrRIDxfnvgBo= Received: from DB6PR0801MB2054.eurprd08.prod.outlook.com (10.168.86.135) by DB6PR0801MB1959.eurprd08.prod.outlook.com (10.168.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Wed, 17 Jul 2019 11:19:56 +0000 Received: from DB6PR0801MB2054.eurprd08.prod.outlook.com ([fe80::5597:75f2:202:4b07]) by DB6PR0801MB2054.eurprd08.prod.outlook.com ([fe80::5597:75f2:202:4b07%12]) with mapi id 15.20.2073.015; Wed, 17 Jul 2019 11:19:56 +0000 From: Joel Hutton To: GCC Patches CC: nd Subject: [Arm][CMSE]Add warn_unused_return attribute to cmse functions Date: Wed, 17 Jul 2019 11:19:56 +0000 Message-ID: <050ee67e-4b18-dced-49bd-717d1aeb5f17@arm.com> user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Joel.Hutton@arm.com; X-Microsoft-Antispam-Untrusted: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(49563074)(7193020); SRVR:DB6PR0801MB1959; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:285;OLM:285; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(136003)(366004)(396003)(376002)(346002)(54534003)(199004)(189003)(478600001)(386003)(64126003)(6506007)(6486002)(31686004)(102836004)(52116002)(8676002)(186003)(6436002)(14444005)(25786009)(256004)(486006)(26005)(65826007)(4326008)(81166006)(81156014)(8936002)(99936001)(6916009)(68736007)(36756003)(99286004)(53936002)(66066001)(65956001)(65806001)(3846002)(6116002)(316002)(5660300002)(2906002)(66616009)(66446008)(66946007)(66556008)(64756008)(66476007)(6512007)(476003)(86362001)(7736002)(2616005)(14454004)(305945005)(31696002)(71200400001)(58126008)(71190400001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB1959; H:DB6PR0801MB2054.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: lYAPw2XeGlxWs4YRADw5EH1WHGyfKYX+B2nHIU0HZDGCU6v3XrxXtDR/VOmzRHW1f3rWLxr7hJDfSWiYb968jLuiBADALrBqlj0J9Rq4dN3ltnECqlHh5Oxl1z1nalEKryrD/X+HW8NV1yWYdvCGl/0v+iztrmMvq1Gk3Rt7IF0F20lLuV42cHcDF5071udFZzolA3uJVKFf6EAdYcsVNL3blCfaAJz9fssFHQzAB5x6D5Pr+PVUFZSGB/+jhXDInsxykHZV+Mo6HnSg6LrLNibJZL7lvFE7+B3ztwh2muAXR9UZ/piaAVTECUZ/TOJNIDoHtxa/9wjjZDZiCvRvoKAcYkYxLQtaqYSjvHsVigsoIMsN3DsG/FacoGz8V6sQyJEszpNKQfFddaCcHpIsCChSh+iCkM6CpQ5Mi/IxKJA= MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Joel.Hutton@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 75f3f96c-b6a1-484e-c90f-08d70aa8b2a4 X-IsSubscribed: yes At present it is possible to call the CMSE functions for checking addresses (such as cmse_check_address_range) and  forget to check/use the return value. This patch makes the interfaces more robust against programmer error by marking these functions with the warn_unused_result attribute. With this set, any use of these functions that does not use the result will produce a warning. This produces a warning on default warn levels when the result of the cmse functions is not used. For the following function: void foo() {     int *data;     cmse_check_address_range((int*)data, 0, 0); } The following warning is emitted: warning: ignoring return value of 'cmse_check_address_range' declared with attribute 'warn_unused_result' [-Wunused-result]     6 |  cmse_check_address_range((int*)data, 0, 0);        |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc/ChangeLog: 2019-07-10  Joel Hutton          * config/arm/arm_cmse.h (cmse_nonsecure_caller): Add warn_unused_result attribute.         (cmse_check_address_range): Add warn_unused_result attribute. libgcc/ChangeLog: 2019-07-10  Joel Hutton          * config/arm/cmse.c (cmse_check_address_range): Add warn_unused_result attribute. 2019-07-10  Joel Hutton          * gcc.target/arm/cmse/cmse-17.c: New test. From 628070faaf157934e6b4c8d7d2d288244467bea6 Mon Sep 17 00:00:00 2001 From: Joel Hutton Date: Wed, 10 Jul 2019 09:59:58 +0100 Subject: [PATCH] CMSE warn unused result --- gcc/config/arm/arm_cmse.h | 2 ++ gcc/testsuite/gcc.target/arm/cmse/cmse-17.c | 10 ++++++++++ libgcc/config/arm/cmse.c | 1 + 3 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/cmse/cmse-17.c diff --git a/gcc/config/arm/arm_cmse.h b/gcc/config/arm/arm_cmse.h index b543cbfe455ae57487be199f7c918eb87db30bf2..a72c46f1a954bd3ba4aefcdbb7a31085d0f583c0 100644 --- a/gcc/config/arm/arm_cmse.h +++ b/gcc/config/arm/arm_cmse.h @@ -164,6 +164,7 @@ __CMSE_TT_ASM (at) /* FIXME: diagnose use outside cmse_nonsecure_entry functions. */ __extension__ static __inline int __attribute__ ((__always_inline__)) +__attribute__ ((warn_unused_result)) cmse_nonsecure_caller (void) { return __builtin_arm_cmse_nonsecure_caller (); @@ -184,6 +185,7 @@ cmse_nonsecure_caller (void) #define CMSE_MPU_READ 8 __extension__ void * +__attribute__ ((warn_unused_result)) cmse_check_address_range (void *, size_t, int); #define cmse_check_pointed_object(p, f) \ diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c new file mode 100644 index 0000000000000000000000000000000000000000..a2cce09afae590461b86397e73e9b98649bed95a --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmse"} */ + +#include + +void foo() +{ + int *data; + cmse_check_address_range((int*)data, 0, 0); /* { dg-warning "ignoring return value" } */ +} diff --git a/libgcc/config/arm/cmse.c b/libgcc/config/arm/cmse.c index 34a46fde2d2fcd9dc181bf5a74dd698de2ebc9bd..0c5a3eaefab49ae07e67b82481fdd0d8dd100227 100644 --- a/libgcc/config/arm/cmse.c +++ b/libgcc/config/arm/cmse.c @@ -30,6 +30,7 @@ address range. See ACLE changes for ARMv8-M. */ void * +__attribute__ ((warn_unused_result)) cmse_check_address_range (void *p, size_t size, int flags) { cmse_address_info_t permb, perme; -- 2.17.1