gcc/ChangeLog
[official-gcc.git] / libcilkrts / runtime / bug.h
blob3b5493bace6bc7e2b8527286e1d3e79c78edacd3
1 /* bug.h -*-C++-*-
3 *************************************************************************
5 * Copyright (C) 2009-2016, Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * *********************************************************************
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
38 * a repository at cilkplus.org. Changes made to this file that are not
39 * submitted through the contribution process detailed at
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
41 * time that a new version is released. Changes only submitted to the
42 * GNU compiler collection or posted to the git repository at
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
44 * not tracked.
46 * We welcome your contributions to this open source project. Thank you
47 * for your assistance in helping us improve Cilk Plus.
48 **************************************************************************/
50 /**
51 * @file bug.h
53 * @brief Support for reporting bugs and debugging.
56 #ifndef INCLUDED_BUG_DOT_H
57 #define INCLUDED_BUG_DOT_H
59 #include "rts-common.h"
60 #include <cilk/common.h>
62 __CILKRTS_BEGIN_EXTERN_C
64 /**
65 * Flush all output, write error message to stderr and abort the execution.
66 * On Windows the error is also written to the debugger.
68 * @param fmt printf-style format string. Any remaining parameters will be
69 * be interpreted based on the format string text.
71 COMMON_PORTABLE NORETURN __cilkrts_bug(const char *fmt,...) cilk_nothrow;
73 #ifndef CILK_ASSERT
75 /** Standard text for failed assertion */
76 COMMON_PORTABLE extern const char *const __cilkrts_assertion_failed;
78 /**
79 * Macro to assert an invariant that must be true. If the statement evalutes
80 * to false, __cilkrts_bug will be called to report the failure and terminate
81 * the application.
83 #define CILK_ASSERT(ex) \
84 (__builtin_expect((ex) != 0, 1) ? (void)0 : \
85 __cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, #ex))
87 #define CILK_ASSERT_MSG(ex, msg) \
88 (__builtin_expect((ex) != 0, 1) ? (void)0 : \
89 __cilkrts_bug(__cilkrts_assertion_failed, __FILE__, __LINE__, \
90 #ex "\n " msg))
91 #endif // CILK_ASSERT
93 /**
94 * Assert that there is no uncaught exception.
96 * Not valid on Windows or Android.
98 * On Android, calling std::uncaught_exception with the stlport library causes
99 * a seg fault. Since we're not supporting exceptions there at this point,
100 * just don't do the check. It works with the GNU STL library, but that's
101 * GPL V3 licensed.
103 COMMON_PORTABLE void cilkbug_assert_no_uncaught_exception(void);
104 #if defined(_WIN32) || defined(__ANDROID__)
105 # define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION()
106 #else
107 # define CILKBUG_ASSERT_NO_UNCAUGHT_EXCEPTION() \
108 cilkbug_assert_no_uncaught_exception()
109 #endif
113 * Call __cilkrts_bug with a standard message that the runtime state is
114 * corrupted and the application is being terminated.
116 COMMON_SYSDEP void abort_because_rts_is_corrupted(void);
118 // Debugging aids
119 #ifndef _DEBUG
120 # define DBGPRINTF(_fmt, ...)
121 #elif defined(_WIN32)
124 * Write debugging output. On windows this is written to the debugger.
126 * @param fmt printf-style format string. Any remaining parameters will be
127 * be interpreted based on the format string text.
129 COMMON_SYSDEP void __cilkrts_dbgprintf(const char *fmt,...) cilk_nothrow;
132 * Macro to write debugging output which will be elided if this is not a
133 * debug build. The macro is currently always elided on non-Windows builds.
135 * @param _fmt printf-style format string. Any remaining parameters will be
136 * be interpreted based on the format string text.
138 # define DBGPRINTF(_fmt, ...) __cilkrts_dbgprintf(_fmt, __VA_ARGS__)
140 #else /* if _DEBUG && !_WIN32 */
141 /* Non-Windows debug logging. Someday we should make GetCurrentFiber()
142 * and GetWorkerFiber() do something.
144 # include <stdio.h>
145 __CILKRTS_INLINE void* GetCurrentFiber() { return 0; }
146 __CILKRTS_INLINE void* GetWorkerFiber(__cilkrts_worker* w) { return 0; }
147 # define DBGPRINTF(_fmt, ...) fprintf(stderr, _fmt, __VA_ARGS__)
148 #endif // _DEBUG
150 __CILKRTS_END_EXTERN_C
152 #endif // ! defined(INCLUDED_BUG_DOT_H)