From patchwork Tue Apr 3 16:26:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dave.pagan@oracle.com X-Patchwork-Id: 894688 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-475775-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZkQ34WjV"; 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 40FvcX0QL5z9s1p for ; Wed, 4 Apr 2018 02:26:51 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=xvXtRDHLIkkMvLvDS+wiH6sParKCxdFMyvSp/bQiq4dMZBzo7z Kttbs8xHBJu7HKJIBWEVhvhyq/wtoLQ+lUGj7ejmybXcdyzgqvGvYqsHSotupI+Y 035ydSdLVzWeX0Df/nU8OpWiSGY9t3MsrM7ionKMRIGtFwitJmLAvyqzo= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=T1I0jIpdgN7MAu11UD/72OMZcU0=; b=ZkQ34WjV2ycadHrLBRm1 LgWpWBlyIWBjeEcvGTrB1aBAveCWY5Md3v1KW7Ddr6+qC9u8Nc3/caUgFQzQOT/h g71EMMByCYORlBOviaFRfpKHmmIpJ1lsKcCWHn8EinuARAn+heqyZwLs4VjxHo4W H+sb1WRkW6ANgXrZgvvZACk= Received: (qmail 129162 invoked by alias); 3 Apr 2018 16:26:44 -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 128878 invoked by uid 89); 3 Apr 2018 16:26:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Apr 2018 16:26:41 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33GD6vx141435 for ; Tue, 3 Apr 2018 16:26:39 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2h4cxkg3n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 03 Apr 2018 16:26:39 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w33GQcCQ005364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 3 Apr 2018 16:26:39 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33GQcoM021598 for ; Tue, 3 Apr 2018 16:26:38 GMT Received: from [192.168.1.21] (/97.86.128.167) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 09:26:38 -0700 To: Gcc Patch List From: dave.pagan@oracle.com Subject: [PATCH] c/55976 -Werror=return-type should error on returning a value from a void function Message-ID: <50f26c0c-e458-9790-6cd4-7ed9299593a4@oracle.com> Date: Tue, 3 Apr 2018 09:26:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8852 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030166 X-IsSubscribed: yes This patch fixes handlng of -Werror=return-type. Currently, even with the flag specified, return type errors remain warnings. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55976 Function c_finish_return (), when calling pedwarn, should specifiy OPT_Wreturn_type as the diagnostic index if warn_return_type is set so that the given diagnostic is generated as an error, not a warning. Patch was successfully bootstrapped and tested on x86_64-linux. --Dave /c 2018-04-03 David Pagan PR c/55976 * c-typeck.c (c_finish_return): If -Wreturn-type enabled (warn_return_type), pass OPT_Wreturn_type to pedwarn so warning is turned into an error when -Werror=return-type specified. /testsuite 2018-04-03 David Pagan PR c/55976 * gcc.dg/noncompile/pr55976.c: New test. Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 259017) +++ gcc/c/c-typeck.c (working copy) @@ -10135,7 +10135,7 @@ c_finish_return (location_t loc, tree retval, tree bool warned_here; if (flag_isoc99) warned_here = pedwarn - (loc, 0, + (loc, warn_return_type ? OPT_Wreturn_type : 0, "% with no value, in function returning non-void"); else warned_here = warning_at @@ -10153,7 +10153,7 @@ c_finish_return (location_t loc, tree retval, tree bool warned_here; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) warned_here = pedwarn - (xloc, 0, + (xloc, warn_return_type ? OPT_Wreturn_type : 0, "% with a value, in function returning void"); else warned_here = pedwarn Index: gcc/testsuite/gcc.dg/noncompile/pr55976.c =================================================================== --- gcc/testsuite/gcc.dg/noncompile/pr55976.c (revision 0) +++ gcc/testsuite/gcc.dg/noncompile/pr55976.c (working copy) @@ -0,0 +1,12 @@ +/* PR c/55976 */ +/* { dg-do compile } */ +/* { dg-options "-Werror=return-type" } */ + +void t () { return 1; } /* { dg-error "return" "function returning void" } */ +int b () { return; } /* { dg-error "return" "function returning non-void" } */ + +int main() +{ + t(); b(); + return 0; +}