From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id B8F8A3858001; Tue, 25 Oct 2022 17:50:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8F8A3858001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666720215; bh=EjnSfL43iEWBDtYIpXVTwY99xuCqycyElLMYjWaSUUQ=; h=From:To:Subject:Date:From; b=PIRJcXbY+fk2QhAyMplEnUobvOf8mq9laV/egr2VU0ZeZ5p6yu/8v36O6lV6Eu00I W3Szn5uXS/L6aOA+u0N8mkHPcIQQSxflAdHDMOrqhInnbn77gSTYQvLvbkitBiisE5 ohidwypXUO8h0wKUSqI6xmXkfErIbQnOf225iKoQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-contracts] c++: minor tweaks X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/devel/c++-contracts X-Git-Oldrev: 249274387130975ae4bb0a29a7b85d35db7eabf6 X-Git-Newrev: 598a58d5539990b56c9a6c73ae1d0ed3445b5498 Message-Id: <20221025175015.B8F8A3858001@sourceware.org> Date: Tue, 25 Oct 2022 17:50:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:598a58d5539990b56c9a6c73ae1d0ed3445b5498 commit 598a58d5539990b56c9a6c73ae1d0ed3445b5498 Author: Jason Merrill Date: Fri Oct 21 10:35:26 2022 -0400 c++: minor tweaks gcc/cp/ChangeLog: * cp-tree.h (struct saved_scope): Move non-bitfield out from between bitfields. (DECL_CDTOR_NEEDS_LABLED_EXIT_P): Remove. * contracts.cc: Add FIXMEs. * pt.cc (register_specialization): Revert reformatting. Diff: --- gcc/cp/cp-tree.h | 11 +---------- gcc/cp/contracts.cc | 15 +++++++++++++-- gcc/cp/pt.cc | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index f011231acb3..28e358a78d6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1944,12 +1944,11 @@ struct GTY(()) saved_scope { int x_processing_template_decl; int x_processing_specialization; int x_processing_constraint; + int x_processing_contract_condition; int suppress_location_wrappers; BOOL_BITFIELD x_processing_explicit_instantiation : 1; BOOL_BITFIELD need_pop_function_context : 1; - int x_processing_contract_condition; - /* Nonzero if we are parsing the discarded statement of a constexpr if-statement. */ BOOL_BITFIELD discarded_stmt : 1; @@ -3250,14 +3249,6 @@ struct GTY(()) lang_decl { (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (NODE) \ || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (NODE)) -/* Nonzero if NODE (a FUNCTION_DECL) is a ctor or dtor that needs the cdtor - label and associated goto built. */ -#define DECL_CDTOR_NEEDS_LABLED_EXIT_P(NODE) \ - (DECL_DESTRUCTOR_P (NODE) \ - || (DECL_CONSTRUCTOR_P (NODE) \ - && (targetm.cxx.cdtor_returns_this () \ - || contract_any_active_p (DECL_CONTRACTS (NODE))))) - /* Nonzero if NODE (a _DECL) is a cloned constructor or destructor. */ #define DECL_CLONED_FUNCTION_P(NODE) \ diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index 0bc8305570d..11fd93362f3 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -41,7 +41,7 @@ along with GCC; see the file COPYING3. If not see "v > 0", // comment, "default", // assertion_level, "default", // assertion_role, - CCS_MAYBE, // continuation_mode + MAYBE_CONTINUE, // continuation_mode ); } @@ -50,9 +50,16 @@ along with GCC; see the file COPYING3. If not see if the contract should not continue on violation. This prevents requiring including and simplifies building the call. + FIXME the overhead would be lower if we write out the contract_violation + object statically and pass it directly to the handler. Though the current + way is more tolerant of layout changes, so maybe leave it alone until the + feature is more mature. + Assumed contracts have a similar transformation that results the body of the if being __builtin_unreachable (); + FIXME use build_assume_call. + Parsing of pre and post contract conditions need to be deferred when the contracts are attached to a member function. The postcondition identifier cannot be used before the deduced return type of an auto function is used, @@ -135,7 +142,11 @@ along with GCC; see the file COPYING3. If not see for each return, or a goto epilogue would need generated similarly to cdtors. For this initial implementation, generating function calls and letting later optimizations decide whether to inline and duplicate the actual - checks or whether to collapse the shared epilogue was chosen. */ + checks or whether to collapse the shared epilogue was chosen. + + FIXME the compiler already handles sharing cleanup code on multiple exit + paths properly, this outlining isn't necessary if we represent the + postcondition as a cleanup (like I already did for dtors). */ #include "config.h" #include "system.h" diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 35da6da7a05..e1503ef8372 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1545,7 +1545,8 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, { if (DECL_TEMPLATE_INSTANTIATION (fn)) { - if (DECL_ODR_USED (fn) || DECL_EXPLICIT_INSTANTIATION (fn)) + if (DECL_ODR_USED (fn) + || DECL_EXPLICIT_INSTANTIATION (fn)) { error ("specialization of %qD after instantiation", fn);