Skip to content

Commit 9885d07

Browse files
author
Timothy Harvey
committed
Added #if control around GCC builtin functions so that the code can be
compiled using non-GCC compilers. This included adding an initialization to a variable that looks(!) like it can reach a use before being initialized (b/c we turned JERRY_UNREACHABLE into a nop) -- an example: int foo; switch (value_can_only_be_one_or_two) case 1: case 2: foo = 5; default: JERRY_UNREACHABLE(); x = foo +1; ...the compiler assumes that the path can go through the default case, which leaves the value of foo undefined. JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey [email protected]
1 parent ec14622 commit 9885d07

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-global.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg, /**< this argument
343343
while (string_curr_p > start_p)
344344
{
345345
ecma_char_t current_char = *(--string_curr_p);
346-
ecma_number_t current_number;
346+
ecma_number_t current_number = ECMA_NUMBER_MINUS_ONE;
347347

348348
if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
349349
{

jerry-core/jrt/jrt.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@
4343
/*
4444
* Conditions' likeliness, unlikeliness.
4545
*/
46-
#define likely(x) __builtin_expect (!!(x), 1)
47-
#define unlikely(x) __builtin_expect (!!(x) , 0)
46+
#ifdef __GNUC__
47+
#define likely(x) __builtin_expect(!!(x), 1)
48+
#define unlikely(x) __builtin_expect(!!(x), 0)
49+
#else /* !__GNUC__ */
50+
#define likely(x) (x)
51+
#define unlikely(x) (x)
52+
#endif /* __GNUC__ */
4853

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

116+
#ifdef __GNUC__
111117
#define JERRY_UNREACHABLE() __builtin_unreachable ()
118+
#else /* !__GNUC__ */
119+
#define JERRY_UNREACHABLE()
120+
#endif /* !__GNUC__ */
112121
#endif /* !JERRY_NDEBUG */
113122

114123
/**

jerry-libc/include/assert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C"
2828
#define assert(x) \
2929
do \
3030
{ \
31-
if (__builtin_expect (!(x), 0)) \
31+
if (!(x)) \
3232
{ \
3333
fprintf (stderr, "%s:%d: %s: Assertion `%s' failed.", __FILE__, __LINE__, __func__, #x); \
3434
abort (); \

0 commit comments

Comments
 (0)