PR c/60988
[official-gcc.git] / libcilkrts / runtime / bug.h
blob1a64bea3a54af6a9df6e843b0194448e992e8a19
1 /* bug.h -*-C++-*-
3 *************************************************************************
5 * @copyright
6 * Copyright (C) 2009-2013, Intel Corporation
7 * All rights reserved.
8 *
9 * @copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * @copyright
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 **************************************************************************/
39 /**
40 * @file bug.h
42 * @brief Support for reporting bugs and debugging.
45 #ifndef INCLUDED_BUG_DOT_H
46 #define INCLUDED_BUG_DOT_H
48 #include "rts-common.h"
49 #include <cilk/common.h>
51 __CILKRTS_BEGIN_EXTERN_C
53 /**
54 * Flush all output, write error message to stderr and abort the execution.
55 * On Windows the error is also written to the debugger.
57 * @param fmt printf-style format string. Any remaining parameters will be
58 * be interpreted based on the format string text.
60 COMMON_PORTABLE NORETURN __cilkrts_bug(const char *fmt,...) cilk_nothrow;
62 #ifndef CILK_ASSERT
64 /** Standard text for failed assertion */
65 COMMON_PORTABLE extern const char *const __cilkrts_assertion_failed;
67 /**
68 * Macro to assert an invariant that must be true. If the statement evalutes
69 * to false, __cilkrts_bug will be called to report the failure and terminate
70 * the application.
72 #define CILK_ASSERT(ex) \
73 (__builtin_expect((ex) != 0, 1) ? (void)0 : \
74 __cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, #ex))
76 #define CILK_ASSERT_MSG(ex, msg) \
77 (__builtin_expect((ex) != 0, 1) ? (void)0 : \
78 __cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, \
79 #ex "\n " msg))
80 #endif // CILK_ASSERT
82 /**
83 * Assert that there is no uncaught exception.
85 * Not valid on Windows or Android.
87 * On Android, calling std::uncaught_exception with the stlport library causes
88 * a seg fault. Since we're not supporting exceptions there at this point,
89 * just don't do the check. It works with the GNU STL library, but that's
90 * GPL V3 licensed.
92 COMMON_PORTABLE void cilkbug_assert_no_uncaught_exception(void);
93 #if defined(_WIN32) || defined(__ANDROID__)
94 # define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION()
95 #else
96 # define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION() \
97 cilkbug_assert_no_uncaught_exception()
98 #endif
102 * Call __cilkrts_bug with a standard message that the runtime state is
103 * corrupted and the application is being terminated.
105 COMMON_SYSDEP void abort_because_rts_is_corrupted(void);
107 // Debugging aids
108 #ifndef _DEBUG
109 # define DBGPRINTF(_fmt, ...)
110 #elif defined(_WIN32)
113 * Write debugging output. On windows this is written to the debugger.
115 * @param fmt printf-style format string. Any remaining parameters will be
116 * be interpreted based on the format string text.
118 COMMON_SYSDEP void __cilkrts_dbgprintf(const char *fmt,...) cilk_nothrow;
121 * Macro to write debugging output which will be elided if this is not a
122 * debug build. The macro is currently always elided on non-Windows builds.
124 * @param _fmt printf-style format string. Any remaining parameters will be
125 * be interpreted based on the format string text.
127 # define DBGPRINTF(_fmt, ...) __cilkrts_dbgprintf(_fmt, __VA_ARGS__)
129 #else /* if _DEBUG && !_WIN32 */
130 /* Non-Windows debug logging. Someday we should make GetCurrentFiber()
131 * and GetWorkerFiber() do something.
133 # include <stdio.h>
134 __CILKRTS_INLINE void* GetCurrentFiber() { return 0; }
135 __CILKRTS_INLINE void* GetWorkerFiber(__cilkrts_worker* w) { return 0; }
136 # define DBGPRINTF(_fmt, ...) fprintf(stderr, _fmt, __VA_ARGS__)
137 #endif // _DEBUG
139 __CILKRTS_END_EXTERN_C
141 #endif // ! defined(INCLUDED_BUG_DOT_H)