Skip to content

Commit

Permalink
Fix CI for macos-latest
Browse files Browse the repository at this point in the history
Add a non-inlineable function for negating a number on macos, bacause
due to a compiler bug `r = -r` was being optimized out, resulting in some
modulo operations failing such as `-1 % -1` or `-1 % 1`.

JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi [email protected]
  • Loading branch information
matetokodi committed May 17, 2024
1 parent 47bd5d4 commit d629959
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions jerry-core/ecma/base/ecma-helpers-number.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <math.h>

#include "ecma-conversion.h"
#ifdef __APPLE__
#include "ecma-helpers.h"
#endif /* __APPLE__ */

#include "lit-char-helpers.h"

Expand Down Expand Up @@ -370,7 +373,11 @@ ecma_number_remainder (ecma_number_t left_num, /**< left operand */

if (ecma_number_is_zero (r) && ecma_number_is_negative (left_num))
{
#ifdef __APPLE__
r = ecma_number_negate (r);
#else /* !__APPLE__ */
r = -r;
#endif /* __APPLE__ */
}

return r;
Expand Down
8 changes: 8 additions & 0 deletions jerry-core/ecma/base/ecma-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,14 @@ ecma_get_current_stack_usage (void)

#endif /* (JERRY_STACK_LIMIT != 0) */

#ifdef __APPLE__
ecma_number_t JERRY_ATTR_CONST
ecma_number_negate (ecma_number_t num)
{
return -num;
} /* ecma_number_negate */
#endif /* __APPLE__ */

/**
* @}
* @}
Expand Down
3 changes: 3 additions & 0 deletions jerry-core/ecma/base/ecma-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ ecma_value_t ecma_get_source_name (const ecma_compiled_code_t *bytecode_p);
#if (JERRY_STACK_LIMIT != 0)
uintptr_t ecma_get_current_stack_usage (void);
#endif /* (JERRY_STACK_LIMIT != 0) */
#ifdef __APPLE__
ecma_number_t ecma_number_negate (ecma_number_t num);
#endif /* __APPLE__ */

/* ecma-helpers-external-pointers.c */
bool ecma_create_native_pointer_property (ecma_object_t *obj_p,
Expand Down

0 comments on commit d629959

Please sign in to comment.