From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 193D93858D3C for ; Mon, 20 Sep 2021 22:50:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 193D93858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x03.wildebeest.org [172.31.17.133]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 4F209300071F; Tue, 21 Sep 2021 00:50:45 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id 6985A2E82F18; Tue, 21 Sep 2021 00:50:45 +0200 (CEST) From: Mark Wielaard To: gcc-rust@gcc.gnu.org Cc: Mark Wielaard Subject: [PATCH] Remove warnings from v0_mangle functions in rust-mangle.cc Date: Tue, 21 Sep 2021 00:49:56 +0200 Message-Id: <20210920224956.147676-1-mark@klomp.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Sep 2021 22:50:49 -0000 There were two warnings in rust-mangle.cc rust-mangle.cc: In function ‘std::string Rust::Compile::v0_mangle_item (const Rust::TyTy::BaseType*, const Rust::Resolver::CanonicalPath&, const string&)’: rust-mangle.cc:198:1: warning: no return statement in function returning non-void rust-mangle.cc: At global scope: rust-mangle.cc:201:1: warning: ‘std::string Rust::Compile::v0_mangle_impl_item (const Rust::TyTy::BaseType*, const Rust::TyTy::BaseType*, const string&, const string&)’ declared ‘static’ but never defined [-Wunused-function] The first results in undefined behaviour, the second points out that the function isn't ever called/used. Fix the first by adding a gcc_unreachable () to turn the calling of the function into an abort (). Fix the second by adding the call in Mangler::mangle_impl_item. And add an implementation simply calling gcc-unreachable (). This turns the warnings and undefined behaviour into explicit runtime aborts when these functions are actually called. --- gcc/rust/backend/rust-mangle.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=rust-mangle-unreachable diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index 840acb992e0..0e6643c64ae 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -195,11 +195,15 @@ v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path, const std::string &crate_name) { auto ty_prefix = v0_type_prefix (ty); + gcc_unreachable (); } static std::string v0_mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty, - const std::string &name, const std::string &crate_name); + const std::string &name, const std::string &crate_name) +{ + gcc_unreachable (); +} std::string Mangler::mangle_item (const TyTy::BaseType *ty, @@ -227,7 +231,7 @@ Mangler::mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty, case Mangler::MangleVersion::LEGACY: return legacy_mangle_impl_item (self, ty, name, crate_name); case Mangler::MangleVersion::V0: - gcc_unreachable (); + return v0_mangle_impl_item (self, ty, name, crate_name); default: gcc_unreachable (); } -- 2.32.0