@@ -16328,6 +16328,7 @@ Floating-point types require additional run-time checking for NaN (see below).
1632816328 an_expr_node_ptr op2 = op1->next;
1632916329 an_expr_node_ptr temp1, temp2, one, zero, minus_one, cmp, unordered, eptr;
1633016330 a_boolean op1_has_side_effects, op2_has_side_effects;
16331+ a_boolean temp1_used, temp2_used;
1633116332 a_type_kind type_kind = expr->variant.operation.type_kind;
1633216333
1633316334 one = spaceship_result_constant_expr(1, expr->type);
@@ -16360,15 +16361,24 @@ Floating-point types require additional run-time checking for NaN (see below).
1636016361 minus_one = spaceship_result_constant_expr(-1, expr->type);
1636116362 op1_has_side_effects = node_has_side_effects(op1, (a_boolean *)NULL);
1636216363 op2_has_side_effects = node_has_side_effects(op2, (a_boolean *)NULL);
16363- temp1 = make_reusable_copy(op1, op1_has_side_effects);
16364- temp2 = make_reusable_copy(op2, op2_has_side_effects);
16364+ temp1 = make_reusable_copy_full(op1, op1_has_side_effects, &temp1_used,
16365+ /*treat_as_potential_prvalue=*/FALSE);
16366+ temp2 = make_reusable_copy_full(op2, op2_has_side_effects, &temp2_used,
16367+ /*treat_as_potential_prvalue=*/FALSE);
1636516368 if (type_kind_is_simple_float_like(type_kind)) {
1636616369 /* If either operand is a NaN, then return
16367- std::partial_ordering::unordered:
16368- (__isnan(temp1 = x) || __isnan(temp2 = y)) ? RT(unordered) :
16370+ std::partial_ordering::unordered. Each operand is evaluated
16371+ exactly once, and the NaN test and the comparisons use the same
16372+ operand values:
16373+ ((temp1 = x), (temp2 = y), __isnan(temp1) | __isnan(temp2))
16374+ ? RT(unordered) :
1636916375 temp1 < temp2 ? RT(-1) :
1637016376 temp2 < temp1 ? RT(1)
1637116377 : RT(0)
16378+ An operand that needs a temporary is assigned to it before the NaN
16379+ test. An operand that needs no temporary is used directly, and its
16380+ assignment to temp1 or temp2 is omitted; it is read only by the NaN
16381+ test and the comparisons.
1637216382 */
1637316383 /* Note that the value of std::partial_ordering::unordered can vary
1637416384 based on the implementation. Look for its definition in the headers
@@ -16386,6 +16396,22 @@ Floating-point types require additional run-time checking for NaN (see below).
1638616396 check_assertion(!ovflo);
1638716397 unordered = spaceship_result_constant_expr((int)unordered_val,
1638816398 expr->type);
16399+ /* Make "__isnan(temp1) | __isnan(temp2)". */
16400+ eptr = make_isnan_call(make_reusable_copy(temp1,
16401+ /*vars_can_change=*/FALSE));
16402+ eptr->next = make_isnan_call(make_reusable_copy(temp2,
16403+ /*vars_can_change=*/FALSE));
16404+ eptr = make_operator_node(eok_or, integer_type(ik_int), eptr);
16405+ /* Evaluate the operands that were copied to temporaries before the
16406+ NaN test. */
16407+ op1->next = NULL;
16408+ op2->next = NULL;
16409+ if (temp2_used) {
16410+ eptr = make_comma_node(op2, eptr);
16411+ } /* if */
16412+ if (temp1_used) {
16413+ eptr = make_comma_node(op1, eptr);
16414+ } /* if */
1638916415 temp2->next = temp1;
1639016416 cmp = make_operator_node(eok_lt, integer_type(ik_int), temp2);
1639116417 cmp->next = one;
@@ -16398,11 +16424,6 @@ Floating-point types require additional run-time checking for NaN (see below).
1639816424 cmp = make_operator_node(eok_lt, integer_type(ik_int), temp1);
1639916425 cmp->next = minus_one;
1640016426 cmp = make_operator_node(eok_question, expr->type, cmp);
16401- op2->next = NULL;
16402- eptr = make_isnan_call(op2);
16403- op1->next = NULL;
16404- eptr->next = make_isnan_call(op1);
16405- eptr = make_operator_node(eok_lor, integer_type(ik_int), eptr);
1640616427 unordered->next = cmp;
1640716428 eptr->next = unordered;
1640816429 set_node_operator(expr, eok_question, expr->type, expr->is_lvalue, eptr);
0 commit comments