Skip to content

Add #if control around GCC builtin functions so that the code can be compiled using non-GCC compilers. #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jerry-core/ecma/builtin-objects/ecma-builtin-global.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg, /**< this argument
while (string_curr_p > start_p)
{
ecma_char_t current_char = *(--string_curr_p);
ecma_number_t current_number;
ecma_number_t current_number = ECMA_NUMBER_MINUS_ONE;

if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply add an assert around lit_char_is_decimal_digit (current_char).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zherczeg While that might work to eliminate the compiler warning, it seems explicitly initializing the variable is still the better option (we should initialize all variables by default to avoid any bugs due to uninitialized variables).

Expand Down
13 changes: 11 additions & 2 deletions jerry-core/jrt/jrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@
/*
* Conditions' likeliness, unlikeliness.
*/
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x) , 0)
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */

/*
* Normally compilers store const(ant)s in ROM. Thus saving RAM.
Expand Down Expand Up @@ -108,7 +113,11 @@ void __noreturn jerry_unreachable (const char *file, const char *function, const
} \
} while (0)

#ifdef __GNUC__
#define JERRY_UNREACHABLE() __builtin_unreachable ()
#else /* !__GNUC__ */
#define JERRY_UNREACHABLE()
#endif /* __GNUC__ */
#endif /* !JERRY_NDEBUG */

/**
Expand Down
2 changes: 1 addition & 1 deletion jerry-libc/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C"
#define assert(x) \
do \
{ \
if (__builtin_expect (!(x), 0)) \
if (!(x)) \
{ \
fprintf (stderr, "%s:%d: %s: Assertion `%s' failed.", __FILE__, __LINE__, __func__, #x); \
abort (); \
Expand Down