From patchwork Tue Jul 16 08:50:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1132530 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-505122-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="Z2Qy9NTk"; 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 45nvHl2tdXz9sN4 for ; Tue, 16 Jul 2019 18:50:43 +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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=etNZGCV9RBlEHybqvrjYyWEKPRvtQHbEo91LooN9icxeWbJevK6Hh 657pU8sk7hOypo6V2bq4dQ/18RSpZCfv9k5verq6PVg+sb6J7VnMEvuvJbaYKVcR tp6vo+ToRXS36csOTSCOajIoVgvhRWvrvzgLBePuBVM1gI7LQ9bMro= 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:subject:date:message-id:mime-version:content-type; s= default; bh=7gwIPwYvZjIfgb08YBWvFeabh8M=; b=Z2Qy9NTk0F/KXTbugsxe bmH1iWnXmPh8ipA6KkH9TALVx0wf8AVo4rffVgslVsOC87CnAhyACS5rmssQkVCs ItBge6IVJocUvlD+dDbyt3Purn+6uJ0znsNUqm9jeTcRpw1GaSuNJeqf/TkAWTMH M0wP3CskHFg07CbOFLRoCd8= Received: (qmail 119705 invoked by alias); 16 Jul 2019 08:50:36 -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 119690 invoked by uid 89); 16 Jul 2019 08:50:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jul 2019 08:50:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 690772B for ; Tue, 16 Jul 2019 01:50:33 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0F73C3F59C for ; Tue, 16 Jul 2019 01:50:32 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Fix -Wreturn-type for static naked functions in C Date: Tue, 16 Jul 2019 09:50:31 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This patch extends the fix for PR53633 to include static functions, which were giving a bogus -Wreturn-type warning for C but not for C++. Tested on aarch64-linux-gnu, x86_64-linux-gnu and armeb-eabi. OK for trunk? OK for GCC 8 and 9 too? I don't think it's a regression, but the current behaviour's very inconsistent and it's affecting real code. Richard 2019-07-16 Richard Sandiford gcc/c/ PR c/53633 * c-decl.c (finish_function): Check targetm.warn_func_return before issuing a -Wreturn-type warning. gcc/testsuite/ * c-c++-common/pr53633-2.c: New test. Index: gcc/c/c-decl.c =================================================================== --- gcc/c/c-decl.c 2019-07-10 19:41:20.543944894 +0100 +++ gcc/c/c-decl.c 2019-07-16 09:46:23.220645712 +0100 @@ -9687,6 +9687,7 @@ finish_function (void) /* Normally, with -Wreturn-type, flow will complain, but we might optimize out static functions. */ && !TREE_PUBLIC (fndecl) + && targetm.warn_func_return (fndecl) && warning (OPT_Wreturn_type, "no return statement in function returning non-void")) TREE_NO_WARNING (fndecl) = 1; Index: gcc/testsuite/c-c++-common/pr53633-2.c =================================================================== --- /dev/null 2019-06-14 15:59:19.298479944 +0100 +++ gcc/testsuite/c-c++-common/pr53633-2.c 2019-07-16 09:46:23.220645712 +0100 @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target naked_functions } */ +/* { dg-options "-O2 -Wall" } */ +/* Check that we do not get warnings about missing return statements + or bogus looking noreturn functions. */ +static int __attribute__((naked)) +foo (void) +{ + __asm__ (""); +} + +static int __attribute__((naked,noreturn)) +bar (void) +{ + __asm__ (""); +} + +int foo_caller (void) { return foo (); } +int bar_caller (void) { return bar (); }