t-harvey 94b6aae52c Added #if control around GCC built-in functions so that the code can be (#1483)
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 t-harvey@ti.com
2017-01-23 12:19:35 +01:00

45 lines
1.1 KiB
C

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JERRY_LIBC_ASSERT_H
#define JERRY_LIBC_ASSERT_H
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifndef NDEBUG
#define assert(x) \
do \
{ \
if (!(x)) \
{ \
fprintf (stderr, "%s:%d: %s: Assertion `%s' failed.", __FILE__, __LINE__, __func__, #x); \
abort (); \
} \
} while (0)
#else /* NDEBUG */
#define assert(x) ((void) 0)
#endif /* !NDEBUG */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !JERRY_LIBC_ASSERT_H */