From patchwork Thu Nov 25 14:16:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 48155 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FEC43858436 for ; Thu, 25 Nov 2021 14:19:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FEC43858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637849996; bh=7l7XojCekkkW2k0g/AQHVabMqe7rHbWpWdW2H6LVHtk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qVzSOEHSAzAgj+NnrcFrf9hasqKQ0QjwNzx9J4kjrHSZ98Uil1qBTt2QkufNMfGC1 3N+vv4Tjt9sx6Lwz7EDOBaJhET6TuFXL8IzgqGknC49jryi0GUVy03Vl6fYl/2VWwR 0MweHzTHYvlkstIXGKLRHtKQgih18Fji6eDFvx5M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 602F8385C40D for ; Thu, 25 Nov 2021 14:16:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 602F8385C40D Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 48B1F1FD34; Thu, 25 Nov 2021 14:16:06 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2FF6813B70; Thu, 25 Nov 2021 14:16:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2uF2Cqaan2F4CAAAMHmgww (envelope-from ); Thu, 25 Nov 2021 14:16:06 +0000 Date: Thu, 25 Nov 2021 15:16:05 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Remove unreachable returns Message-ID: <80qqs862-prn1-369p-94n4-qq8qoq34os1@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: polacek@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This removes unreachable return statements as diagnosed by the -Wunreachable-code patch. Some cases are more obviously an improvement than others - in fact some may get you the idea to replace them with gcc_unreachable () instead, leading to cases of the 'Remove unreachable gcc_unreachable () at the end of functions' patch. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK? Comments? Feel free to approve select cases only. Thanks, Richard. 2021-11-25 Richard Biener * vec.c (qsort_chk): Do not return the void return value from the noreturn qsort_chk_error. * ccmp.c (expand_ccmp_expr_1): Remove unreachable return. * df-scan.c (df_ref_equal_p): Likewise. * dwarf2out.c (is_base_type): Likewise. (add_const_value_attribute): Likewise. * fixed-value.c (fixed_arithmetic): Likewise. * gimple-fold.c (gimple_fold_builtin_fputs): Likewise. * gimple-ssa-strength-reduction.c (stmt_cost): Likewise. * graphite-isl-ast-to-gimple.c (gcc_expression_from_isl_expr_op): Likewise. (gcc_expression_from_isl_expression): Likewise. * ipa-fnsummary.c (will_be_nonconstant_expr_predicate): Likewise. * lto-streamer-in.c (lto_input_mode_table): Likewise. gcc/c-family/ * c-opts.c (c_common_post_options): Remove unreachable return. * c-pragma.c (handle_pragma_target): Likewise. (handle_pragma_optimize): Likewise. gcc/c/ * c-typeck.c (c_tree_equal): Remove unreachable return. * c-parser.c (get_matching_symbol): Likewise. libgomp/ * oacc-plugin.c (GOMP_PLUGIN_acc_default_dim): Remove unreachable return. --- gcc/c-family/c-opts.c | 5 +---- gcc/c-family/c-pragma.c | 10 ++-------- gcc/c/c-parser.c | 1 - gcc/c/c-typeck.c | 2 -- gcc/ccmp.c | 2 -- gcc/df-scan.c | 1 - gcc/dwarf2out.c | 3 --- gcc/fixed-value.c | 1 - gcc/gimple-fold.c | 1 - gcc/gimple-ssa-strength-reduction.c | 1 - gcc/graphite-isl-ast-to-gimple.c | 4 ---- gcc/ipa-fnsummary.c | 1 - gcc/lto-streamer-in.c | 7 ++----- gcc/vec.c | 10 +++++----- libgomp/oacc-plugin.c | 1 - 15 files changed, 10 insertions(+), 40 deletions(-) diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 2030eb1a4cd..93845d57dee 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -1109,10 +1109,7 @@ c_common_post_options (const char **pfilename) out_stream = fopen (out_fname, "w"); if (out_stream == NULL) - { - fatal_error (input_location, "opening output file %s: %m", out_fname); - return false; - } + fatal_error (input_location, "opening output file %s: %m", out_fname); init_pp_output (out_stream); } diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index 3663eb1cfbb..c4ed4205820 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -916,10 +916,7 @@ handle_pragma_target(cpp_reader *ARG_UNUSED(dummy)) } if (token != CPP_STRING) - { - GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string"); - return; - } + GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string"); /* Strings are user options. */ else @@ -991,10 +988,7 @@ handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy)) } if (token != CPP_STRING && token != CPP_NUMBER) - { - GCC_BAD ("%<#pragma GCC optimize%> is not a string or number"); - return; - } + GCC_BAD ("%<#pragma GCC optimize%> is not a string or number"); /* Strings/numbers are user options. */ else diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index f312630448f..af2bb5bc8cc 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1132,7 +1132,6 @@ get_matching_symbol (enum cpp_ttype type) { default: gcc_unreachable (); - return ""; case CPP_CLOSE_PAREN: return "("; case CPP_CLOSE_BRACE: diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index b71358e1821..7524304f2bd 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -15984,8 +15984,6 @@ c_tree_equal (tree t1, tree t2) default: gcc_unreachable (); } - /* We can get here with --disable-checking. */ - return false; } /* Returns true when the function declaration FNDECL is implicit, diff --git a/gcc/ccmp.c b/gcc/ccmp.c index d581cfadf06..616fe035e79 100644 --- a/gcc/ccmp.c +++ b/gcc/ccmp.c @@ -273,8 +273,6 @@ expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq) return NULL_RTX; return expand_ccmp_next (op1, code, tmp, prep_seq, gen_seq); } - - return NULL_RTX; } /* Main entry to expand conditional compare statement G. diff --git a/gcc/df-scan.c b/gcc/df-scan.c index 3dbda7aa52c..1baa6e7350b 100644 --- a/gcc/df-scan.c +++ b/gcc/df-scan.c @@ -2059,7 +2059,6 @@ df_ref_equal_p (df_ref ref1, df_ref ref2) default: gcc_unreachable (); } - return false; } diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index e1d6a79ecd7..1677923a439 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -13359,8 +13359,6 @@ is_base_type (tree type) return 0; gcc_unreachable (); } - - return 0; } /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE @@ -20240,7 +20238,6 @@ add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl) /* No other kinds of rtx should be possible here. */ gcc_unreachable (); } - return false; } /* Determine whether the evaluation of EXPR references any variables diff --git a/gcc/fixed-value.c b/gcc/fixed-value.c index 78134bc510f..fdfb700ae66 100644 --- a/gcc/fixed-value.c +++ b/gcc/fixed-value.c @@ -756,7 +756,6 @@ fixed_arithmetic (FIXED_VALUE_TYPE *f, int icode, const FIXED_VALUE_TYPE *op0, default: gcc_unreachable (); } - return false; } /* Compare fixed-point values by tree_code. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 73f090bb14c..1f54219fe43 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -2993,7 +2993,6 @@ gimple_fold_builtin_fputs (gimple_stmt_iterator *gsi, default: gcc_unreachable (); } - return false; } /* Fold a call to the __mem{cpy,pcpy,move,set}_chk builtin. diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c index a92cf03c1f3..8943c57b7a9 100644 --- a/gcc/gimple-ssa-strength-reduction.c +++ b/gcc/gimple-ssa-strength-reduction.c @@ -763,7 +763,6 @@ stmt_cost (gimple *gs, bool speed) } gcc_unreachable (); - return 0; } /* Look up the defining statement for BASE_IN and return a pointer diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c index 1ad68a1d473..8c5cd33f451 100644 --- a/gcc/graphite-isl-ast-to-gimple.c +++ b/gcc/graphite-isl-ast-to-gimple.c @@ -526,8 +526,6 @@ gcc_expression_from_isl_expr_op (tree type, __isl_take isl_ast_expr *expr, default: gcc_unreachable (); } - - return NULL_TREE; } /* Converts an isl AST expression E back to a GCC expression tree of @@ -557,8 +555,6 @@ gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *expr, default: gcc_unreachable (); } - - return NULL_TREE; } /* Creates a new LOOP corresponding to isl_ast_node_for. Inserts an diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c index cb13d2e4b3c..6c1cdf17e47 100644 --- a/gcc/ipa-fnsummary.c +++ b/gcc/ipa-fnsummary.c @@ -2042,7 +2042,6 @@ will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi, debug_tree (expr); gcc_unreachable (); } - return false; } diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c index eb8a7dc57b0..536de3a71b7 100644 --- a/gcc/lto-streamer-in.c +++ b/gcc/lto-streamer-in.c @@ -1963,11 +1963,8 @@ lto_input_mode_table (struct lto_file_decl_data *file_data) const char *data = lto_get_summary_section_data (file_data, LTO_section_mode_table, &len); if (! data) - { - internal_error ("cannot read LTO mode table from %s", - file_data->file_name); - return; - } + internal_error ("cannot read LTO mode table from %s", + file_data->file_name); unsigned char *table = ggc_cleared_vec_alloc (1 << 8); file_data->mode_table = table; diff --git a/gcc/vec.c b/gcc/vec.c index 6d767cc12c1..bdbd1ad6e04 100644 --- a/gcc/vec.c +++ b/gcc/vec.c @@ -229,23 +229,23 @@ qsort_chk (void *base, size_t n, size_t size, sort_r_cmp_fn *cmp, void *data) if (CMP (i1, i2)) break; else if (CMP (i2, i1)) - return ERR2 (i1, i2); + ERR2 (i1, i2); size_t lim1 = LIM (i2 - i1), lim2 = LIM (n - i2); /* Verify that other pairs within current span compare equal. */ for (i = i1 + 1; i + 1 < i2; i++) for (j = i + 1; j < i1 + lim1; j++) if (CMP (i, j)) - return ERR3 (i, i1, j); + ERR3 (i, i1, j); else if (CMP (j, i)) - return ERR2 (i, j); + ERR2 (i, j); /* Verify that elements within this span compare less than elements beyond the span. */ for (i = i1; i < i2; i++) for (j = i2; j < i2 + lim2; j++) if (CMP (i, j) >= 0) - return ERR3 (i, i1, j); + ERR3 (i, i1, j); else if (CMP (j, i) <= 0) - return ERR2 (i, j); + ERR2 (i, j); } #undef ERR3 #undef ERR2 diff --git a/libgomp/oacc-plugin.c b/libgomp/oacc-plugin.c index e25b462eff0..98166fe5cd1 100644 --- a/libgomp/oacc-plugin.c +++ b/libgomp/oacc-plugin.c @@ -62,7 +62,6 @@ GOMP_PLUGIN_acc_default_dim (unsigned int i) if (i >= GOMP_DIM_MAX) { gomp_fatal ("invalid dimension argument: %d", i); - return -1; } return goacc_default_dims[i]; }