From patchwork Mon Nov 13 13:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 164476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1190529vqg; Mon, 13 Nov 2023 05:12:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfgRZL550C4DvzYxmr6CsnfCPYlXlYwcz9T/J3FA1Hudh1L1wRmcjuk+4rOnnWfze3xhuF X-Received: by 2002:a05:622a:11cc:b0:421:b37c:fdf6 with SMTP id n12-20020a05622a11cc00b00421b37cfdf6mr8693392qtk.43.1699881133193; Mon, 13 Nov 2023 05:12:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699881133; cv=pass; d=google.com; s=arc-20160816; b=ZcQ8n41KP4fiaNjd5WIyBazT1Ad88F54b5S0GiqnJNAwpctLaGFvykMlT5hNrAznU5 /qoAlvA0RVLFQmKekWiTA4d3roCNGqjCHkt0+BofPd1tcL0B8oZfXSs+P5e9ugeBQlbY VvlO/c082wd62xlhoiX7sPjonmz29x/jhrf2oAFRDJ9W/yU4SFiGhiavB6Y/cY95ra4J LU2C5qqrowKRRWWRgTN0T+eRl1ZtEhUivIn8EnxsY1kX0v732NAtIIIC7N53LCmIiJiI 4FHF8Q4upgGI+A9t5c5kPjhzJeU0564Qqq6J8FtbtQaiv3i53evBk+jZYzkQVQhHVc6p /+Mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent:date :references:message-id:in-reply-to:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=/R1WyRYEKtD++R6AYAefvr2eevcygZxClsrrmhxSiyQ=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=MAkJ9120ZBAGttp35RNKUB+jJ3LwbkY8naKGvUYZINENQoDOzzY7Z1p3+eI5U757v1 jODtfuf7k1dk/6GHTfko4++zQQXOSbwR8FJDh4WYY++Kj942KumhVg+X+4mXPMMKqOtk 5+gaQhQ3mfPclLLnhGRUyh16nuJY/4zUxIqDdQrMUpOD5wdeBTP+pnk/CXQblkj2BdpP LDLcaEdVp4Mz/uLoaIZ8B9z3XgKthexx2Fz9SKnoW+6+cGFKm/6l0xtOUdlvxQk70YkQ 2Z9nxsw2rlmGcooGX8V2c+l3wBMjKXKeRdOdEM081UVyPeqf6Q+tTLvLFFSJzhZhr5qB dXnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IvYopvEd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j7-20020ac85f87000000b00418070c227dsi4794963qta.349.2023.11.13.05.12.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:12:13 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IvYopvEd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 970EC388B686 for ; Mon, 13 Nov 2023 13:11:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 32846383DF9F for ; Mon, 13 Nov 2023 13:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32846383DF9F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 32846383DF9F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881081; cv=none; b=cP9eiNKsCr8E9uZ6jr9VL3ZUOEvmaGLeTIIcXwif3sRs8716DSFu0o8F6NBE+C92NqQSxChSh0Q2+Qtl2BYr/RhnVtvEjNNf+FQTeEfKRHXdqoEuSoTR4dPpXkpsIlbz4dr7l8v0FIUPisEQes9Q3D9mmL2Tic1TNrbG+5zLijY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881081; c=relaxed/simple; bh=xRCB1DV7tY60/JTwn+qs4TAnTy0TZszn6zkDXBdN/3U=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=An1ESR70zxLmMivFapO0rceffvCuQxNnjAJf7M5j5josPAWFffGG/AhSMO06BYA1hv9AJ8SBsg6GqEEb+z2uIci0804VqyyIsf8z47nYrfH5pZJayZVGCwNfFLhYrf7+RfiNEIndElLf6woZ/JWJKlmKNIPKBM/uWYZi85QXf70= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699881078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/R1WyRYEKtD++R6AYAefvr2eevcygZxClsrrmhxSiyQ=; b=IvYopvEdgfQrQPWpYrrWzXDqIrwcY0SzEQqmMgvnjHrhnArMijLaON3X14/LQkScN8hqhw sMl8svY/CTcP0xWyJAKmXYJqTV91MSg087a5NeBTG72hI9bnO2xWagzQVkYeDAm/pMFt73 cmRNZsLxezKWlMRVFXG9+OyFBkb6+A4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-496-5rH8oJOANYO3DpA5oViuPA-1; Mon, 13 Nov 2023 08:11:17 -0500 X-MC-Unique: 5rH8oJOANYO3DpA5oViuPA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30B69280D463 for ; Mon, 13 Nov 2023 13:11:17 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0476BC0FE05 for ; Mon, 13 Nov 2023 13:11:15 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH 5/6] c: Turn -Wreturn-mismatch into a pedpermerror In-Reply-To: Message-ID: References: X-From-Line: f036ee4b116bfe608ff3cf094f1f42f2c8235761 Mon Sep 17 00:00:00 2001 Date: Mon, 13 Nov 2023 14:11:14 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782454559148724146 X-GMAIL-MSGID: 1782454559148724146 gcc/ * doc/invoke.texi (Warning Options): Document changes. gcc/c/ * c-typeck.cc (c_finish_return): Issue a permerror for mismatching pointers to builtins. For mismatching other pointers, issue a pedpermerror. gcc/testsuite/ * gcc.dg/20030906-1.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/20030906-1a.c: New test. Copied from gcc.dg/20030906-1.c. Expect the error. * gcc.dg/20030906-2.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/20030906-2a.c: New test. Copied from gcc.dg/20030906-2.c. Expect the error. * gcc.dg/Wreturn-mismatch-1.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/Wreturn-mismatch-1a.c: New test. Copied from gcc.dg/Wreturn-mismatch-1.c. Expect the error. * gcc.dg/Wreturn-mismatch-2.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/Wreturn-mismatch-2a.c: New test. Copied from gcc.dg/Wreturn-mismatch-2.c. Expect the error. * gcc.dg/diagnostic-range-bad-return.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/diagnostic-range-bad-return-2.c: New test. Copied from gcc.dg/diagnostic-range-bad-return.c. Expect the error. * gcc.dg/pr105635-2.c: Expect -Wreturn-mismatch error. * gcc.dg/pr23075.c: Build with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/pr23075-2.c: New test. Copied from gcc.dg/pr23075.c. Expect the error. * gcc.dg/pr29521.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/pr29521-a.c: New test. Copied from gcc.dg/pr29521.c. Expect error. * gcc.dg/pr67730.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. * gcc.dg/pr67730-a.c: New test. Copied from gcc.dg/pr67730-a.c. Expect error. * gcc.target/powerpc/conditional-return.c: Compile with -fpermissive due to expected -Wreturn-mismatch error. --- gcc/c/c-typeck.cc | 6 ++- gcc/doc/invoke.texi | 6 ++- gcc/testsuite/gcc.dg/20030906-1.c | 2 +- gcc/testsuite/gcc.dg/20030906-1a.c | 21 ++++++++ gcc/testsuite/gcc.dg/20030906-2.c | 2 +- gcc/testsuite/gcc.dg/20030906-2a.c | 21 ++++++++ gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c | 2 +- gcc/testsuite/gcc.dg/Wreturn-mismatch-1a.c | 40 ++++++++++++++ gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c | 2 +- gcc/testsuite/gcc.dg/Wreturn-mismatch-2a.c | 41 +++++++++++++++ .../gcc.dg/diagnostic-range-bad-return-2.c | 52 +++++++++++++++++++ .../gcc.dg/diagnostic-range-bad-return.c | 2 +- gcc/testsuite/gcc.dg/pr105635-2.c | 2 +- gcc/testsuite/gcc.dg/pr23075-2.c | 14 +++++ gcc/testsuite/gcc.dg/pr23075.c | 2 +- gcc/testsuite/gcc.dg/pr29521-a.c | 15 ++++++ gcc/testsuite/gcc.dg/pr29521.c | 2 +- gcc/testsuite/gcc.dg/pr67730-a.c | 11 ++++ gcc/testsuite/gcc.dg/pr67730.c | 2 +- .../gcc.target/powerpc/conditional-return.c | 2 +- 20 files changed, 234 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/20030906-1a.c create mode 100644 gcc/testsuite/gcc.dg/20030906-2a.c create mode 100644 gcc/testsuite/gcc.dg/Wreturn-mismatch-1a.c create mode 100644 gcc/testsuite/gcc.dg/Wreturn-mismatch-2a.c create mode 100644 gcc/testsuite/gcc.dg/diagnostic-range-bad-return-2.c create mode 100644 gcc/testsuite/gcc.dg/pr23075-2.c create mode 100644 gcc/testsuite/gcc.dg/pr29521-a.c create mode 100644 gcc/testsuite/gcc.dg/pr67730-a.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 9d7bdbb4523..be376758b82 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11192,7 +11192,9 @@ c_finish_return (location_t loc, tree retval, tree origtype) && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE) { no_warning = true; - if (emit_diagnostic (flag_isoc99 ? DK_PEDWARN : DK_WARNING, + if (emit_diagnostic (flag_isoc99 && !flag_pedantic_errors + ? DK_PERMERROR + : flag_isoc99 ? DK_PEDWARN : DK_WARNING, loc, OPT_Wreturn_mismatch, "% with no value," " in function returning non-void")) @@ -11205,7 +11207,7 @@ c_finish_return (location_t loc, tree retval, tree origtype) current_function_returns_null = 1; bool warned_here; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) - warned_here = pedwarn + warned_here = pedpermerror (xloc, OPT_Wreturn_mismatch, "% with a value, in function returning void"); else diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3a1b9b00f24..6635a136cd9 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6183,6 +6183,7 @@ that have their own flag: -Wimplicit-int @r{(C)} -Wint-conversion @r{(C)} -Wnarrowing @r{(C++)} +-Wreturn-mismatch @r{(C)} } The @option{-fpermissive} option is the default for historic C language @@ -7373,7 +7374,10 @@ Attempting to use the return value of a non-@code{void} function other than @code{main} that flows off the end by reaching the closing curly brace that terminates the function is undefined. -This warning is specific to C and enabled by default. +This warning is specific to C and enabled by default. In C99 and later +language dialects, it is treated as an error. It an be downgraded +to a warning using @option{-fpermissive} (along with other warnings), +or for just this warning, with @option{-Wno-error=return-mismatch}. @opindex Wreturn-type @opindex Wno-return-type diff --git a/gcc/testsuite/gcc.dg/20030906-1.c b/gcc/testsuite/gcc.dg/20030906-1.c index c416f55ee75..6ba5b3d770a 100644 --- a/gcc/testsuite/gcc.dg/20030906-1.c +++ b/gcc/testsuite/gcc.dg/20030906-1.c @@ -2,7 +2,7 @@ Copyright (C) 2003 Free Software Foundation Inc. */ /* { dg-do compile } */ -/* { dg-options "-O -finline-functions -Wreturn-type" } */ +/* { dg-options "-fpermissive -O -finline-functions -Wreturn-type" } */ extern int i; extern int foo (void); diff --git a/gcc/testsuite/gcc.dg/20030906-1a.c b/gcc/testsuite/gcc.dg/20030906-1a.c new file mode 100644 index 00000000000..46ca1771a4d --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030906-1a.c @@ -0,0 +1,21 @@ +/* Bug 9862 -- Spurious warnings with -finline-functions. + Copyright (C) 2003 Free Software Foundation Inc. */ + +/* { dg-do compile } */ +/* { dg-options "-O -finline-functions -Wreturn-type" } */ + +extern int i; +extern int foo (void); +extern int bar (void); + +int foo (void) +{ + if( i ) return 0; + else return 1; +} + +int bar (void) +{ + if( i ) return; /* { dg-error "'return' with no value, in function returning non-void" } */ + else return 1; +} diff --git a/gcc/testsuite/gcc.dg/20030906-2.c b/gcc/testsuite/gcc.dg/20030906-2.c index 1191133e6a0..a85d91f46f3 100644 --- a/gcc/testsuite/gcc.dg/20030906-2.c +++ b/gcc/testsuite/gcc.dg/20030906-2.c @@ -2,7 +2,7 @@ Copyright (C) 2003 Free Software Foundation Inc. */ /* { dg-do compile } */ -/* { dg-options "-O -finline-functions -Wreturn-type" } */ +/* { dg-options "-fpermissive -O -finline-functions -Wreturn-type" } */ extern int i; extern int foo (void); diff --git a/gcc/testsuite/gcc.dg/20030906-2a.c b/gcc/testsuite/gcc.dg/20030906-2a.c new file mode 100644 index 00000000000..a6ffbacb46d --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030906-2a.c @@ -0,0 +1,21 @@ +/* Bug 9862 -- Spurious warnings with -finline-functions. + Copyright (C) 2003 Free Software Foundation Inc. */ + +/* { dg-do compile } */ +/* { dg-options "-O -finline-functions -Wreturn-type" } */ + +extern int i; +extern int foo (void); +extern int bar (void); + +int foo (void) +{ + if( i ) return; /* { dg-error "'return' with no value, in function returning non-void" } */ + else return 1; +} + +int bar (void) +{ + if( i ) return 0; + else return 1; +} diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c index 3bad847ecf7..aef6782cbeb 100644 --- a/gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ void f1 (void); diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-1a.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-1a.c new file mode 100644 index 00000000000..70c7c9ddb86 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-1a.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void f1 (void); + +int +f2 (void) +{ + f1 (); +} + +static inline int +f3 (void) +{ + f1 (); +} + +void +f4 (void) +{ + return 1; /* { dg-error "'return' with a value\[^\n\r\]*-Wreturn-mismatch" } */ +} + +void +f5 (void) +{ + return f1 (); /* { dg-bogus "ISO C" } */ +} + +int +f6 (void) +{ + return; /* { dg-error "'return' with no value\[^\n\r\]*-Wreturn-mismatch" } */ +} + +int +f7 (void) +{ + return f1 (); /* { dg-error "void value not ignored as it ought to be" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c index 49eb5a5a95c..08811024b7e 100644 --- a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wall" } */ +/* { dg-options "-fpermissive -Wall" } */ void f1 (void); diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2a.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2a.c new file mode 100644 index 00000000000..836651ed925 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2a.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void f1 (void); + +int +f2 (void) +{ + f1 (); +} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ + +static inline int +f3 (void) +{ + f1 (); +} /* { dg-warning "no return statement in function\[^\n\r\]*-Wreturn-type" } */ + +void +f4 (void) +{ + return 1; /* { dg-error "with a value,\[^\n\r\]*-Wreturn-mismatch" } */ +} + +void +f5 (void) +{ + return f1 (); +} + +int +f6 (void) +{ + return; /* { dg-error "with no value,\[^\n\r\]*Wreturn-mismatch" } */ +} + +int +f7 (void) +{ + return f1 (); /* { dg-error "void value not ignored as it ought to be" } */ +} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ + diff --git a/gcc/testsuite/gcc.dg/diagnostic-range-bad-return-2.c b/gcc/testsuite/gcc.dg/diagnostic-range-bad-return-2.c new file mode 100644 index 00000000000..2fe8d341dba --- /dev/null +++ b/gcc/testsuite/gcc.dg/diagnostic-range-bad-return-2.c @@ -0,0 +1,52 @@ +/* { dg-options "-fdiagnostics-show-caret -Wreturn-local-addr" } */ + +int *address_of_local (void) +{ + int some_local; + return &some_local; /* { dg-warning "function returns address of local variable" } */ +/* { dg-begin-multiline-output "" } + return &some_local; + ^~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +void surplus_return_when_void_1 (void) +{ + return 500; /* { dg-error "'return' with a value, in function returning void" } */ +/* { dg-begin-multiline-output "" } + return 500; + ^~~ + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + void surplus_return_when_void_1 (void) + ^~~~~~~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +void surplus_return_when_void_2 (int i, int j) +{ + return i * j; /* { dg-error "'return' with a value, in function returning void" } */ +/* { dg-begin-multiline-output "" } + return i * j; + ~~^~~ + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + void surplus_return_when_void_2 (int i, int j) + ^~~~~~~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +int missing_return_value (void) +{ + return; /* { dg-error "'return' with no value, in function returning non-void" } */ +/* { dg-begin-multiline-output "" } + return; + ^~~~~~ + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + int missing_return_value (void) + ^~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +/* TODO: ideally we'd underline the return type i.e. "int", but that + location isn't captured. */ +} diff --git a/gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c b/gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c index 063fdf1f636..b74481b870c 100644 --- a/gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c +++ b/gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c @@ -1,4 +1,4 @@ -/* { dg-options "-fdiagnostics-show-caret -Wreturn-local-addr" } */ +/* { dg-options "-fpermissive -fdiagnostics-show-caret -Wreturn-local-addr" } */ int *address_of_local (void) { diff --git a/gcc/testsuite/gcc.dg/pr105635-2.c b/gcc/testsuite/gcc.dg/pr105635-2.c index 807eef0b7cd..019dbc7e557 100644 --- a/gcc/testsuite/gcc.dg/pr105635-2.c +++ b/gcc/testsuite/gcc.dg/pr105635-2.c @@ -7,5 +7,5 @@ void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type foo (int x, int y) /* { dg-error "return type defaults to 'int'" } */ { /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */ /* { dg-message "declared here" "" { target *-*-* } .-2 } */ - return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */ + return (x >= 0) != (y < 0); /* { dg-error "'return' with a value, in function returning void" } */ } diff --git a/gcc/testsuite/gcc.dg/pr23075-2.c b/gcc/testsuite/gcc.dg/pr23075-2.c new file mode 100644 index 00000000000..0702ddf1a66 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr23075-2.c @@ -0,0 +1,14 @@ +/* PR c/23075 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wreturn-type" } */ + +int +foo (void) +{ + return; /* { dg-error "with no value" } */ +} /* { dg-bogus "control reaches end" } */ + +int +bar (void) +{ +} /* { dg-warning "control reaches end" } */ diff --git a/gcc/testsuite/gcc.dg/pr23075.c b/gcc/testsuite/gcc.dg/pr23075.c index 2d85fb0650f..28baf41006a 100644 --- a/gcc/testsuite/gcc.dg/pr23075.c +++ b/gcc/testsuite/gcc.dg/pr23075.c @@ -1,6 +1,6 @@ /* PR c/23075 */ /* { dg-do compile } */ -/* { dg-options "-O2 -Wreturn-type" } */ +/* { dg-options "-O2 -fpermissive -Wreturn-type" } */ int foo (void) diff --git a/gcc/testsuite/gcc.dg/pr29521-a.c b/gcc/testsuite/gcc.dg/pr29521-a.c new file mode 100644 index 00000000000..2c6a48b7e30 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr29521-a.c @@ -0,0 +1,15 @@ +/* PR 29521 : warning for return with expression in function returning void */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void func (void) { } + +void func2 (void) +{ + return func (); +} + +void func3 (void) +{ + return 1; /* { dg-error "'return' with a value" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr29521.c b/gcc/testsuite/gcc.dg/pr29521.c index b6fb535fab7..cd431514ed2 100644 --- a/gcc/testsuite/gcc.dg/pr29521.c +++ b/gcc/testsuite/gcc.dg/pr29521.c @@ -1,6 +1,6 @@ /* PR 29521 : warning for return with expression in function returning void */ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ void func (void) { } diff --git a/gcc/testsuite/gcc.dg/pr67730-a.c b/gcc/testsuite/gcc.dg/pr67730-a.c new file mode 100644 index 00000000000..08737cc9811 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67730-a.c @@ -0,0 +1,11 @@ +/* PR c/67730 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#include + +void +fn1 (void) +{ + return NULL; /* { dg-error "10:.return. with a value" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr67730.c b/gcc/testsuite/gcc.dg/pr67730.c index 54d73a62cf8..cc51858c531 100644 --- a/gcc/testsuite/gcc.dg/pr67730.c +++ b/gcc/testsuite/gcc.dg/pr67730.c @@ -1,6 +1,6 @@ /* PR c/67730 */ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ #include diff --git a/gcc/testsuite/gcc.target/powerpc/conditional-return.c b/gcc/testsuite/gcc.target/powerpc/conditional-return.c index 6b3ef5f52ca..c6491216752 100644 --- a/gcc/testsuite/gcc.target/powerpc/conditional-return.c +++ b/gcc/testsuite/gcc.target/powerpc/conditional-return.c @@ -1,7 +1,7 @@ /* Check that a conditional return is used. */ /* { dg-do compile } */ -/* { dg-options "-O2 -w" } */ +/* { dg-options "-O2 -fpermissive -w" } */ /* { dg-final { scan-assembler {\mbeqlr\M} } } */