1. 15 Jun, 2020 1 commit
  2. 08 Jun, 2020 1 commit
    • Jeff Chapman II's avatar
      WIP TMP Rewrite guarded function transform · dfbecc91
      Jeff Chapman II authored
      Originally, a guarded function is transformed in a way that alters the
      original function:
      int fun(int v)
        [[ pre: v > 0 ]] [[ post r: r < 0 ]]
        return -v;
      would turn into
      int __unchecked_fun(int v) { return -v; }
      int fun(int v) {
        [[ assert: v > 0 ]];
        auto &&__r = __unchecked_fun(v);
        [[ assert: __r < 0 ]];
        return __r;
      The goal is to leave the original decl alone and instead generate calls
      to pre/post functions:
      void __pre_fun(int v) { [[ assert: v > 0 ]]; }
      int __post_fun(int v, int __r) { [[ assert: __r < 0 ]]; }
      int fun(int v) {
        return __post_fun(v, -v);
      This sides steps a number of issues with having to rewrite the bodies or
      rewrite the parsed conditions as the parameters to the original function
      changes (as happens during redeclaration). The ultimate goal is to get
      something that optimizes well along the lines of
      int fun(int v) {
        [[ assert: v > 0 ]];
        auto &&__r = -v;
        goto out;
        [[ assert: __r < 0 ]];
        return __r;
      With the idea being that multiple return statements could collapse the
      function epilogue after inlining the pre/post functions. clang is able
      to collapse common function epilogues, while gcc needs -O3 -Os combined.
      We're already doing this manually for cdtors due to the way they work.
        Handling around guarded template members of template classes is
        incomplete and results in a few errors.
        We're currently only generating a single pre/post function for a
        virtual member, which results in incorrect diagnostics but less code
  3. 07 Jun, 2020 1 commit
    • Jeff Chapman's avatar
      c++: Fix contracts feature test macros · 403869cf
      Jeff Chapman authored
      2020-05-13  Jeff Chapman II  <[email protected]>
      	* c-cppbuiltin.c (c_cpp_builtins): Only define contracts related
      	feature test macros if flag_contracts is set.
      	* g++.dg/cpp2a/contracts-ft1.C: New test.
      	* g++.dg/cpp2a/contracts-pre2a1.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre2a2.C: Ditto.
  4. 07 May, 2020 1 commit
  5. 06 May, 2020 2 commits
    • Jeff Chapman II's avatar
      update to current git master · ada85fda
      Jeff Chapman II authored
    • Jeff Chapman's avatar
      c++: Diagnose misapplied contracts. Allow contracts after virt specifier. · 477b7961
      Jeff Chapman authored
      2020-05-05  Jeff Chapman II  <[email protected]>
      	Diagnose misapplied contracts. Allow contracts after virt specifier.
      	* cp-tree.h (diagnose_misapplied_contracts): New.
      	* decl.c (diagnose_misapplied_contracts): Same.
      	(check_tag_decl): Use above to diagnose contracts on tag decls.
      	(grokdeclarator): Diagnose contracts in declspecs and declaration
      	attrlist if any. Extract diagnostic into
      	* parser.c (cp_separate_contracts): Now works when passed in contracts
      	list is not already empty.
      	(cp_parser_statement): Initialize contract_attrs before call to
      	(cp_parser_decl_specifier_seq): Diagnose invalid application of
      	(cp_parser_class_head): Ditto.
      	(cp_parser_member_declaration): Handle contracts appearing after a
      	function's virt-specifier.
      2020-05-05  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-pre1.C: New test cases for misapplied
      	* g++.dg/cpp2a/contracts-override.C: New test.
  6. 23 Apr, 2020 2 commits
    • Jeff Chapman's avatar
      c++: Move and refactor contract option handling code · cd7a543e
      Jeff Chapman authored
      2020-04-22  Jeff Chapman II  <[email protected]>
      	Move contract related option handling code from c-opts to
      	cxx-contracts. Fix style.
      	* cxx-contracts.c (role_name_equal): New helpers for comparing
      	possibly colon terminated names so we don't require mutated copies of
      	argv values.
      	(handle_OPT_fcontract_role_): Now copies less and cleans up after
      	(handle_OPT_fcontract_semantic_): No longer allocates at all.
    • Jeff Chapman's avatar
      c++: Cleanup contracts implementation · 6379d8c8
      Jeff Chapman authored
      2020-04-21  Jeff Chapman II  <[email protected]>
      	* input.c (get_source): Moved from cp/parser.c.
      	* input.h (get_source): Same.
      2020-04-21  Jeff Chapman II  <[email protected]>
      	* cxx-contracts.c (get_contract_role): Fix style.
      2020-04-21  Jeff Chapman II  <[email protected]>
      	Fix style and comments in several places.
      	* parser.c (get_source): Move to input.c.
      	* pt.c (tsubst_expr): Remove outdated TODO and unneeded
      	* search.c (check_final_overrider): Reword guarded override
      2020-04-21  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-redecl5.C: New test case.
      2019-04-21  Jeff Chapman II  <[email protected]>
      	* include/std/contract (contract_violation_continuation_mode): Remove
  7. 21 Apr, 2020 1 commit
    • Jeff Chapman's avatar
      c++: Treat contracts on statics and friends as complete class contexts · 17ee5fab
      Jeff Chapman authored
      2020-04-20  Jeff Chapman II  <[email protected]>
      	Correctly treat contract attributes on friend and static member
      	function decls as a complete class context.
      	* cp-tree.h (CONTRACT_SOURCE_LOCATION_WRAPPER): New helper.
      	(pending_guarded_decls): Newly extern.
      	(defer_guarded_contract_match): Now accepts both a source function and
      	list of contract attributes to distinguish between overrides and
      	* decl.c (merge_contracts): Defer contract matching when the new or
      	existing contracts are not fully parsed. Use new contract location
      	(pending_guarded_overrides): Renamed to:
      	(pending_guarded_decls): and made extern.
      	(defer_guarded_contract_match): Accepts and stores both a function and
      	list of contracts.
      	(match_deferred_contracts): Uses the contract location helpers.
      	Determines arguments to match_contract_conditions based on the
      	information saved by defer_guarded_contract_match.
      	(finish_function): New checking assertion that there are no
      	outstanding pending contract matching required.
      	* parser.c (cp_parser_contracts): Now accepts a defer bool if the
      	caller knows the contracts cannot be parsed yet.
      	(cp_parser_member_declaration): Defer parsing of contracts when
      	calling cp_parser_contracts on friend decls.
      	(cp_parser_save_member_function_body): Always defer parsing of
      	contracts since we in an incomplete type.
      	(begin_contract_scope): Instead of calling inject_this_parameter,
      	directly inject the this parameter that's already been added to the
      	function's parameter list.
      	(cp_parser_late_parsing_for_contracts): Defer if this is a friend
      	decl. If we are parsing now, parse any deferred matches as well.
      	* search.c (check_final_overrider): Pass the basefn to
      2020-04-20  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-redecl2.C: Remove outdated comment.
      	* g++.dg/cpp2a/contracts-redecl7.C: Additional cases around friends.
      	* g++.dg/cpp2a/contracts-redecl8.C: New test for failures in contract
      	matching on friend decls.
      	* g++.dg/cpp2a/contracts-friend1.C: New test.
  8. 20 Apr, 2020 3 commits
    • Jeff Chapman's avatar
      c++: Fix template contract condition conversion diagnostic · 7fbedf5f
      Jeff Chapman authored
      2020-04-19  Jeff Chapman II  <[email protected]>
      	* parser.c (cp_parser_contract_condition): If needed, build a location
      	wrapper around the parsed condition for later diagnostics.
      	* pt.c (tsubst_contract): Use the original condition location as the
      	location of the substituted condition.
      	* semantics.c (start_contract): Remove FIXME about incorrect
      	diagnostic location.
      2020-04-19  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-conversion1.C: New test.
    • Jeff Chapman's avatar
      c++: Use TREE_LANG_FLAGs for computed contract_semantic · e854de69
      Jeff Chapman authored
      2020-04-16  Jeff Chapman II  <[email protected]>
      	* cp-tree.h (get_contract_semantic): Use TREE_LANG_FLAG_0, 2, and 3
      	instead of spare1.
      	(set_contract_semantic): Ditto.
    • Jeff Chapman's avatar
      c++: Cleanup contracts parsing and semantics · b7a83b44
      Jeff Chapman authored
      2020-04-15  Jeff Chapman II  <[email protected]>
      	* parser.c: Cleanup outdated FIXMEs.
      	(cp_parser_cache_contract_condition): Use
      	* search.c (check_final_overrider): Remove outdated FIXME.
      	* semantics.c: Cleanup outdated FIXMEs.
      	(start_checked_function_definition): Begin BCS_FN_BODY instead of
      	(finish_checked_function_definition): Use finish_compound_stmt instead
      	of finish_function_body.
      	(start_postcondition_statement): push_stmt_list to capture the built
      	(finish_postcondition_statement): Replace inlined version of
      	finish_compound_stmt with finish_compound_stmt and pop_stmt_list,
      	using the new list created in start_postcondition_statement.
      2020-04-15  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-pre1.C: Add more missing close parse tests.
  9. 12 Apr, 2020 4 commits
    • Jeff Chapman's avatar
      c++: Remove check_always_continue contract semantic · a2a119e3
      Jeff Chapman authored
      2020-04-12  Jeff Chapman II  <[email protected]>
      	* cxx-contracts.h (contract_semantic): Remove CCS_ALWAYS.
      	(contract_continuation): Remove ALWAYS_CONTINUE.
      	* cxx-contracts.c (valid_configs): Remove CCS_ALWAYS values.
      	(lookup_concrete_semantic): Remove CCS_ALWAYS cases.
      	(setup_default_contract_role): Remove CCS_ALWAYS from default %review
      	(map_contract_semantic): Remove CCS_ALWAYS case.
      2020-04-12  Jeff Chapman II  <[email protected]>
      	* cp-tree.h (cp_tree_index): Remove CPTI_ON_CONTRACT_VIOLATION_ALWAYS.
      	(on_contract_violation_always_fn): Remove.
      	* except.c (init_exception_processing): Remove always continue handler
      	* semantics.c (build_contract_handler_fn): Remove ALWAYS_CONTINUE
      	related logic, including hacky workarounds.
      	(build_contract_check): Remove CCS_ALWAYS case.
      2020-04-12  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts1.C: Ensure check_always_continue emits a
      	* g++.dg/cpp2a/contracts23.C: Remove.
    • Jeff Chapman's avatar
      c++: Fix large return types on guarded functions · 54ebaa10
      Jeff Chapman authored
      2020-04-08  Jeff Chapman II  <[email protected]>
      	* tree-inline.c (remap_unchecked_body): Leave DECL_RESULT alone.
      2020-04-08  Jeff Chapman II  <[email protected]>
      	* semantics.c (build_checked_function_definition): Swap checked and
      	unchecked DECL_RESULT so any references in the body of the unchecked
      	function still point to its DECL_RESULT. This fixes a different
      	transform for large return types.
      2020-04-08  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-large-return.c: New test.
    • Jeff Chapman's avatar
      c++ contracts: Cleanup based on upstream feedback. · 2bd8ad83
      Jeff Chapman authored
      2020-04-06  Jeff Chapman II  <[email protected]>
      	* Makefile.in (C_COMMON_OBJS): Rename contract to cxx-contracts.
      	* gimplify.c (gimplify_expr): Remove old debugging code.
      2020-04-06  Jeff Chapman II  <[email protected]>
      	* c-common.c: Remove old debugging include.
      	* c-opts.c: Rename contract.h to cxx-contracts.h.
      	* contract.c: Rename to:
      	* cxx-contracts.c: Add copyright block; fix include.
      	* contract.h: Rename to:
      	* cxx-contracts.h: Fix copyright block.
      2020-04-06  Jeff Chapman II  <[email protected]>
      	* cp-tree.h (function_declarator_p): Newly public.
      	* decl.c (match_contract_conditions): Invert return value to match
      	name, update comments.
      	(match_contracts): Ditto, update usage of above.
      	(grokdeclarator): Use function_declarator_p, look for unseparated
      	contract attributes in std_attributes too.
      	* except.c (init_exception_processing): Remove TODO.
      	* parser.c (function_declarator_p): No longer static.
      	(stringify_tree): Remove.
      	(cp_parser_contract_condition): Use expr_to_string.
      	(begin_contract_scope): Use inject_parm_decls and
      	* semantics.c (build_arg_list): Use forward_parm.
      	(build_contract_check): Update comments; this is only called during
      	genericization and does not need to be done at gimplification time.
      2020-04-06  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-pre1.c: New cases.
    • Jeff Chapman's avatar
      c++: Move DECL_UNCHECKED_RESULT out of lang_decl_fn · f00ef7e2
      Jeff Chapman authored
      2020-04-02  Jeff Chapman II  <[email protected]>
      	Store DECL_UNCHECKED_RESULT in separate hash_map instead of bloating
      	* cp-tree.h (lang_decl_fn): Remove unchecked_result.
      	(set_unchecked_result): New.
      	(get_unchecked_result): Ditto.
      	(DECL_UNCHECKED_RESULT): Use above.
      	* decl.c (duplicate_decls): Remove contracts and unchecked_result from
      	to-be-reused FUNCTION_DECL nodes before freeing them.
      	* pt.c (tsubst_contract_conditions): Use set_unchecked_result instead
      	(instantiate_template_1): Ditto.
      	(regenerate_decl_from_template): Ditto.
      	* semantics.c (decl_unchecked_results): New hash_map to track
      	unchecked results.
      	(build_unchecked_result): Use set_unchecked_result.
      	(get_unchecked_result): New.
      	(set_unchecked_result): Ditto.
  10. 02 Apr, 2020 5 commits
    • Jeff Chapman's avatar
      c++: Store contracts in DECL_ATTRIBUTES · 9afe371b
      Jeff Chapman authored
      2020-03-25  Jeff Chapman II  <[email protected]>
      	* contract.h (cxx23_contract_attribute_p): Make global extern.
      2020-03-25  Jeff Chapman II  <[email protected]>
      	Store contracts in DECL_ATTRIBUTES.
      	* cp-tree.h (lang_decl_fn): Remove separate contracts member.
      	(find_contract): New.
      	(DECL_CONTRACTS): Use the above.
      	(CONTRACT_CHAIN): New. Find next contract attribute.
      	(remove_contract_attributes): New.
      	(set_decl_contracts): New.
      	* decl.c: Use above methods for interacting with contracts.
      	* pt.c: Ditto.
      	* semantics.c: Ditto.
      	(remove_contract_attributes): New. Deletes contract attributes from
      	regular attributes.
    • Jeff Chapman's avatar
      c++: Replace DECL_DEFERRED_CONTRACTS with a separate hash map for guarded overrides · d5f8801b
      Jeff Chapman authored
      2020-03-25  Jeff Chapman II  <[email protected]>
      	Stop using DECL_DEFERRED_CONTRACTS in favor of separate hash map for
      	guarded overrides.
      	* cp-tree.h (DECL_CONTRACTS): Look directly at contracts since
      	deferred contracts have been moved elsewhere.
      	(defer_guarded_contract_match): New.
      	* decl.c: Use DECL_CONTRACTS instead of DECL_DEFERRED_CONTRACTS.
      	(merge_contracts): Save original decl and location in contracts.
      	(pending_guarded_overrides): New.
      	(defer_guarded_contract_match): New.
      	(match_deferred_contracts): Use the above instead of
      	* parser.c (cp_separate_contracts): Fix whitespace.
      	(cp_parser_late_parsing_for_contracts): Only worry about parsing
      	non-deferred contracts.
      	* pt.c (instantiate_class_template_1): We no longer need extra logic
      	to handle deferred contracts here.
      	(tsubst_contract_conditions_r): Handle DECL_CONTRACTS directly.
      	(instantiate_template_1): Ditto.
      	* search.c (check_final_overrider): Ditto.
      	Use defer_guarded_contract_match if needed.
      	* semantics.c (build_unchecked_function_declaration): Handle
      	DECL_CONTRACTS directly.
      2020-03-25  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-redecl5.c: New cases.
    • Jeff Chapman's avatar
      c++: Use DECL_SEEN_WITHOUT_CONTRACTS_P instead of sentinel value · c438d449
      Jeff Chapman authored
      	* cp-tree.h (DECL_SEEN_WITHOUT_CONTRACTS_P): New.
      	* decl.c (match_contracts): Use DECL_SEEN_WITHOUT_CONTRACTS_P instead
      	of looking for sentinel value.
      	(merge_contracts): Ditto.
      	(duplicate_decls): Save DECL_SEEN_WITHOUT_CONTRACTS_P.
    • Jeff Chapman's avatar
      c++: Fix contract related naming · 6b084b0d
      Jeff Chapman authored
      2020-03-17  Jeff Chapman II  <[email protected]>
      	* contract.h: Remove cpp_ prefixes.
      	* contract.c: Ditto.
      	* c-opts.c: Ditto.
    • Jeff Chapman's avatar
      c++: Decouple contract parsing from concrete semantic mapping · d7a7fec7
      Jeff Chapman authored
      2020-03-17  Jeff Chapman II  <[email protected]>
      	* contract.h (contract_mode): Rewrite in terms of constructors instead
      	of setters.
      	(map_contract_semantic): New.
      	(map_contract_level): New.
      	* contract.c (+map_contract_semantic): New. Map a soure level contract
      	semantic to a contract_semantic enum.
      	(map_contract_level): New. Map a source level contract level to a
      	contract_level enum.
      2020-03-17  Jeff Chapman II  <[email protected]>
      	* cp-tree.h (CONTRACT_LITERAL_MODE_P): Examine shape of contract
      	configuration instead of TREE_CONSTANT flag.
      	* parser.c (cp_parser_contract_role): Just parse a role; don't build
      	the contract_mode along with it.
      	(cp_parser_contract_mode_opt): Ditto.
      	(cp_parser_contract_attribute_spec): Let start_contract build the
      	* semantics.c (contract_config_to_mode): New.
      	(compute_contract_concrete_semantic): New; extracted from
      	(start_contract): Use the above.
      2020-03-17  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts-config1.C: New test.
  11. 24 Mar, 2020 2 commits
  12. 22 Jan, 2020 2 commits
  13. 13 Nov, 2019 2 commits
  14. 06 Nov, 2019 2 commits
    • Jeff Chapman's avatar
      Fix ICE clearing contracts on type specializations · 1bff2811
      Jeff Chapman authored
      2019-11-06  Jeff Chapman II  <[email protected]>
      	* pt.c (instantiate_template_1): Only clear DECL_DEFERRED_CONTRACTS on
      	specializations of functions.
    • Jeff Chapman's avatar
      Hide contracts behind new -fcontracts flag · 33959539
      Jeff Chapman authored
      2019-11-06  Jeff Chapman II  <[email protected]>
      	* c.opt (fcontracts): New flag.
      2019-11-06  Jeff Chapman II  <[email protected]>
      	* decl.c (start_decl): Error on nondefining declarations of members
      	outside a class when flag_contracts is false.
      	* parser.c (cp_parser_contracts): Check flag_contracts instead of
      	(cp_parser_contract_attribute_spec): Ditto.
      2019-11-06  Jeff Chapman II  <[email protected]>
      	* g++.dg/cpp2a/contracts1.C: Add -fconcepts.
      	* g++.dg/cpp2a/contracts2.C: Ditto.
      	* g++.dg/cpp2a/contracts3.C: Ditto.
      	* g++.dg/cpp2a/contracts4.C: Ditto.
      	* g++.dg/cpp2a/contracts5.C: Ditto.
      	* g++.dg/cpp2a/contracts6.C: Ditto.
      	* g++.dg/cpp2a/contracts7.C: Ditto.
      	* g++.dg/cpp2a/contracts8.C: Ditto.
      	* g++.dg/cpp2a/contracts9.C: Ditto.
      	* g++.dg/cpp2a/contracts10.C: Ditto.
      	* g++.dg/cpp2a/contracts11.C: Ditto.
      	* g++.dg/cpp2a/contracts12.C: Ditto.
      	* g++.dg/cpp2a/contracts13.C: Ditto.
      	* g++.dg/cpp2a/contracts14.C: Ditto.
      	* g++.dg/cpp2a/contracts15.C: Ditto.
      	* g++.dg/cpp2a/contracts16.C: Ditto.
      	* g++.dg/cpp2a/contracts17.C: Ditto.
      	* g++.dg/cpp2a/contracts18.C: Ditto.
      	* g++.dg/cpp2a/contracts19.C: Ditto.
      	* g++.dg/cpp2a/contracts20.C: Ditto.
      	* g++.dg/cpp2a/contracts22.C: Ditto.
      	* g++.dg/cpp2a/contracts23.C: Ditto.
      	* g++.dg/cpp2a/contracts24.C: Ditto.
      	* g++.dg/cpp2a/contracts25.C: Ditto.
      	* g++.dg/cpp2a/contracts35.C: Ditto.
      	* g++.dg/cpp2a/contracts-access1.C: Ditto.
      	* g++.dg/cpp2a/contracts-assume1.C: Ditto.
      	* g++.dg/cpp2a/contracts-assume2.C: Ditto.
      	* g++.dg/cpp2a/contracts-assume3.C: Ditto.
      	* g++.dg/cpp2a/contracts-assume4.C: Ditto.
      	* g++.dg/cpp2a/contracts-assume5.C: Ditto.
      	* g++.dg/cpp2a/contracts-ctor-dtor1.C: Ditto.
      	* g++.dg/cpp2a/contracts-ctor-dtor2.C: Ditto.
      	* g++.dg/cpp2a/contracts-cv1.C: Ditto.
      	* g++.dg/cpp2a/contracts-deduced1.C: Ditto.
      	* g++.dg/cpp2a/contracts-ignore1.C: Ditto.
      	* g++.dg/cpp2a/contracts-ignore2.C: Ditto.
      	* g++.dg/cpp2a/contracts-post1.C: Ditto.
      	* g++.dg/cpp2a/contracts-post2.C: Ditto.
      	* g++.dg/cpp2a/contracts-post3.C: Ditto.
      	* g++.dg/cpp2a/contracts-post4.C: Ditto.
      	* g++.dg/cpp2a/contracts-post5.C: Ditto.
      	* g++.dg/cpp2a/contracts-post6.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre1.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre2.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre3.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre4.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre5.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre6.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre7.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre9.C: Ditto.
      	* g++.dg/cpp2a/contracts-pre10.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl1.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl2.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl3.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl4.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl5.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl6.C: Ditto.
      	* g++.dg/cpp2a/contracts-redecl7.C: Ditto.
      	* g++.dg/cpp2a/contracts-tmpl-spec1.C: Ditto.
      	* g++.dg/cpp2a/contracts-tmpl-spec2.C: Ditto.
  15. 04 Nov, 2019 2 commits
  16. 28 Oct, 2019 2 commits
  17. 23 Oct, 2019 1 commit
  18. 22 Oct, 2019 1 commit
  19. 15 Oct, 2019 1 commit
  20. 09 Oct, 2019 4 commits