Skip to content

Commit

Permalink
Merge pull request gcc-mirror#29 from iains/contracts-nonattr-p1494r4
Browse files Browse the repository at this point in the history
Contracts nonattr p1494r4
  • Loading branch information
villevoutilainen authored Oct 28, 2024
2 parents 955a69f + 9190710 commit b6ed54a
Show file tree
Hide file tree
Showing 13 changed files with 557 additions and 503 deletions.
4 changes: 4 additions & 0 deletions gcc/builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8341,6 +8341,10 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
expand_builtin_unreachable ();
return const0_rtx;

case BUILT_IN_OBSERVABLE:
/* Emits no code. */
return const0_rtx;

CASE_FLT_FN (BUILT_IN_SIGNBIT):
case BUILT_IN_SIGNBITD32:
case BUILT_IN_SIGNBITD64:
Expand Down
1 change: 1 addition & 0 deletions gcc/builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CO
DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNREACHABLE_TRAP, "unreachable trap", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNREACHABLE, "unreachable", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_GCC_BUILTIN (BUILT_IN_OBSERVABLE, "observable", BT_FN_VOID, ATTR_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNWIND_INIT, "unwind_init", BT_FN_VOID, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_UPDATE_SETJMP_BUF, "update_setjmp_buf", BT_FN_VOID_PTR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_VA_COPY, "va_copy", BT_FN_VOID_VALIST_REF_VALIST_ARG, ATTR_NOTHROW_LEAF_LIST)
Expand Down
1 change: 1 addition & 0 deletions gcc/c-family/c-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ const struct c_common_resword c_common_reswords[] =
{ "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 },
{ "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 },
{ "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
{ "__builtin_observable", RID_BUILTIN_OBSERVABLE, D_CXXONLY },
{ "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
{ "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 },
{ "__builtin_stdc_bit_ceil", RID_BUILTIN_STDC, D_CONLY },
Expand Down
1 change: 1 addition & 0 deletions gcc/c-family/c-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ enum rid
/* C++ extensions */
RID_ADDRESSOF,
RID_BUILTIN_LAUNDER,
RID_BUILTIN_OBSERVABLE,
RID_BUILTIN_BIT_CAST,

/* C++11 */
Expand Down
4 changes: 4 additions & 0 deletions gcc/c-family/c.opt
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,10 @@ fcontract-disable-optimized-checks
C++ Var(flag_contract_disable_optimized_checks) Init(0)
-fcontract-disable-optimized-checks Disable optimisation of contract checks.

fcontract-disable-check-epochs
C++ Var(flag_contract_disable_check_epochs) Init(0)
-fcontract-disable-epoch-checks Disable insertion of epoch markers after each contract check.

fcoroutines
C++ LTO Var(flag_coroutines)
Enable C++ coroutines (experimental).
Expand Down
4 changes: 4 additions & 0 deletions gcc/cp/constexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,10 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
/* These builtins shall be ignored during constant expression
evaluation. */
return void_node;
case BUILT_IN_OBSERVABLE:
if (ctx->manifestly_const_eval == mce_true)
return void_node;
/* FALLTHROUGH */
case BUILT_IN_UNREACHABLE:
case BUILT_IN_TRAP:
if (!*non_constant_p && !ctx->quiet)
Expand Down
22 changes: 17 additions & 5 deletions gcc/cp/contracts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2101,13 +2101,17 @@ build_contract_check (tree contract)

/* Add the contract statement CONTRACT to the current block if valid. */

static void
static bool
emit_contract_statement (tree contract)
{
/* Only add valid contracts. */
if (get_contract_semantic (contract) != CCS_INVALID
&& CONTRACT_CONDITION (contract) != error_mark_node)
add_stmt (contract);
if (contract == error_mark_node
|| CONTRACT_CONDITION (contract) == error_mark_node
|| get_contract_semantic (contract) == CCS_INVALID)
return false;

add_stmt (contract);
return true;
}

/* Generate the statement for the given contract attribute by adding the
Expand Down Expand Up @@ -2180,7 +2184,15 @@ remap_and_emit_conditions (tree fn, tree condfn, tree_code code)
{
contract = copy_node (contract);
remap_contract (fn, condfn, contract, /*duplicate_p=*/false);
emit_contract_statement (contract);
if (!emit_contract_statement (contract))
continue;
if (flag_contract_disable_check_epochs)
continue;
/* Insert a std::observable () epoch marker. */
tree fn = builtin_decl_explicit (BUILT_IN_OBSERVABLE);
releasing_vec vec;
fn = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
finish_expr_stmt (fn);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions gcc/cp/cp-objcp-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ names_builtin_p (const char *name)
case RID_BUILTIN_SHUFFLE:
case RID_BUILTIN_SHUFFLEVECTOR:
case RID_BUILTIN_LAUNDER:
case RID_BUILTIN_OBSERVABLE:
case RID_BUILTIN_ASSOC_BARRIER:
case RID_BUILTIN_BIT_CAST:
case RID_OFFSETOF:
Expand Down
1 change: 1 addition & 0 deletions gcc/cp/cxxapi-data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@
<cstdint>,uintptr_t,1,cxx11
# <cstdio> TODO
# <cstdlib> TODO
<cstdlib>,observable,1,cxx11
# <cstring> TODO
# <ctime> TODO
# <cuchar> TODO
Expand Down
17 changes: 17 additions & 0 deletions gcc/cp/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7726,6 +7726,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
case RID_BUILTIN_SHUFFLE:
case RID_BUILTIN_SHUFFLEVECTOR:
case RID_BUILTIN_LAUNDER:
case RID_BUILTIN_OBSERVABLE:
case RID_BUILTIN_ASSOC_BARRIER:
{
vec<tree, va_gc> *vec;
Expand Down Expand Up @@ -7769,6 +7770,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
}
break;

case RID_BUILTIN_OBSERVABLE:
if (vec->length () == 0)
{
tree fn = builtin_decl_explicit (BUILT_IN_OBSERVABLE);
releasing_vec vec;
postfix_expression = finish_call_expr (fn, &vec, false, false,
tf_warning_or_error);
}
else
{
error_at (loc, "%<__builtin_observable%> does not take"
" arguments");
postfix_expression = error_mark_node;
}
break;

case RID_BUILTIN_ASSOC_BARRIER:
if (vec->length () == 1)
postfix_expression = build1_loc (loc, PAREN_EXPR,
Expand Down
2 changes: 2 additions & 0 deletions gcc/cp/std-name-hint.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ uint_least64_t, "<cstdint>", cxx11
uint_least8_t, "<cstdint>", cxx11
uintmax_t, "<cstdint>", cxx11
uintptr_t, "<cstdint>", cxx11
# <cstdlib>
observable, "<cstdlib>", cxx11
# <deque>
deque, "<deque>", cxx98
# <exception>
Expand Down
Loading

0 comments on commit b6ed54a

Please sign in to comment.