annotate libcilkrts/runtime/bug.cpp @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* bug.cpp -*-C++-*-
kono
parents:
diff changeset
2 *
kono
parents:
diff changeset
3 *************************************************************************
kono
parents:
diff changeset
4 *
kono
parents:
diff changeset
5 * Copyright (C) 2009-2016, Intel Corporation
kono
parents:
diff changeset
6 * All rights reserved.
kono
parents:
diff changeset
7 *
kono
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
9 * modification, are permitted provided that the following conditions
kono
parents:
diff changeset
10 * are met:
kono
parents:
diff changeset
11 *
kono
parents:
diff changeset
12 * * Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
14 * * Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in
kono
parents:
diff changeset
16 * the documentation and/or other materials provided with the
kono
parents:
diff changeset
17 * distribution.
kono
parents:
diff changeset
18 * * Neither the name of Intel Corporation nor the names of its
kono
parents:
diff changeset
19 * contributors may be used to endorse or promote products derived
kono
parents:
diff changeset
20 * from this software without specific prior written permission.
kono
parents:
diff changeset
21 *
kono
parents:
diff changeset
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kono
parents:
diff changeset
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kono
parents:
diff changeset
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kono
parents:
diff changeset
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kono
parents:
diff changeset
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
kono
parents:
diff changeset
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
kono
parents:
diff changeset
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kono
parents:
diff changeset
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
kono
parents:
diff changeset
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
kono
parents:
diff changeset
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
kono
parents:
diff changeset
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
kono
parents:
diff changeset
33 * POSSIBILITY OF SUCH DAMAGE.
kono
parents:
diff changeset
34 *
kono
parents:
diff changeset
35 * *********************************************************************
kono
parents:
diff changeset
36 *
kono
parents:
diff changeset
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
kono
parents:
diff changeset
38 * a repository at cilkplus.org. Changes made to this file that are not
kono
parents:
diff changeset
39 * submitted through the contribution process detailed at
kono
parents:
diff changeset
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
kono
parents:
diff changeset
41 * time that a new version is released. Changes only submitted to the
kono
parents:
diff changeset
42 * GNU compiler collection or posted to the git repository at
kono
parents:
diff changeset
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
kono
parents:
diff changeset
44 * not tracked.
kono
parents:
diff changeset
45 *
kono
parents:
diff changeset
46 * We welcome your contributions to this open source project. Thank you
kono
parents:
diff changeset
47 * for your assistance in helping us improve Cilk Plus.
kono
parents:
diff changeset
48 **************************************************************************/
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 #include "bug.h"
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 #include <exception>
kono
parents:
diff changeset
53 #include <stdio.h>
kono
parents:
diff changeset
54 #include <stdarg.h>
kono
parents:
diff changeset
55 #include <stdlib.h>
kono
parents:
diff changeset
56 #ifdef _WIN32
kono
parents:
diff changeset
57 # include "windows-clean.h"
kono
parents:
diff changeset
58 # include "internal/abi.h"
kono
parents:
diff changeset
59 # include "cilktools/cilkscreen.h"
kono
parents:
diff changeset
60 # include <crtdbg.h>
kono
parents:
diff changeset
61 #endif
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 __CILKRTS_BEGIN_EXTERN_C
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 COMMON_PORTABLE const char *const __cilkrts_assertion_failed =
kono
parents:
diff changeset
66 "%s:%d: cilk assertion failed: %s\n";
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 COMMON_PORTABLE NORETURN __cilkrts_bug(const char *fmt,...) cilk_nothrow
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 #if defined (_WIN32) && defined(_DEBUG)
kono
parents:
diff changeset
71 _CRTIMP void __cdecl _wassert(__in_z const wchar_t * _Message,
kono
parents:
diff changeset
72 __in_z const wchar_t *_File,
kono
parents:
diff changeset
73 __in unsigned _Line);
kono
parents:
diff changeset
74 char message[256];
kono
parents:
diff changeset
75 wchar_t wmessage[256];
kono
parents:
diff changeset
76 va_list l;
kono
parents:
diff changeset
77 va_start(l, fmt);
kono
parents:
diff changeset
78 _vsnprintf_s(message, 256, _TRUNCATE, fmt, l);
kono
parents:
diff changeset
79 va_end(l);
kono
parents:
diff changeset
80 _snwprintf_s(wmessage, 256, _TRUNCATE, _CRT_WIDE("%S"),
kono
parents:
diff changeset
81 message); /* widen */
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 // Force asserts to go to stderr and the debugger. This isn't polite, but
kono
parents:
diff changeset
84 // we're about to kill the app anyway and it will prevent our tests from
kono
parents:
diff changeset
85 // hanging
kono
parents:
diff changeset
86 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE| _CRTDBG_MODE_DEBUG);
kono
parents:
diff changeset
87 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 _wassert(wmessage, _CRT_WIDE(__FILE__), __LINE__);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 // If there's a debugger attached, give it a chance to look at the failure
kono
parents:
diff changeset
92 if (IsDebuggerPresent())
kono
parents:
diff changeset
93 DebugBreak();
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 abort();
kono
parents:
diff changeset
96 /* __asm int 3 */
kono
parents:
diff changeset
97 #else
kono
parents:
diff changeset
98 /* To reduce user confusion, write all user-generated output
kono
parents:
diff changeset
99 before the system-generated error message. */
kono
parents:
diff changeset
100 va_list l;
kono
parents:
diff changeset
101 fflush(NULL);
kono
parents:
diff changeset
102 va_start(l, fmt);
kono
parents:
diff changeset
103 vfprintf(stderr, fmt, l);
kono
parents:
diff changeset
104 va_end(l);
kono
parents:
diff changeset
105 fflush(stderr);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 #ifndef _WIN32
kono
parents:
diff changeset
108 abort();
kono
parents:
diff changeset
109 #endif
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 #endif
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 exit(1);
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 COMMON_PORTABLE void cilkbug_assert_no_uncaught_exception(void)
kono
parents:
diff changeset
117 {
kono
parents:
diff changeset
118 bool uncaught = std::uncaught_exception();
kono
parents:
diff changeset
119 CILK_ASSERT(!uncaught);
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 COMMON_SYSDEP void abort_because_rts_is_corrupted(void)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 __cilkrts_bug("The Cilk Plus runtime system detected a corruption "
kono
parents:
diff changeset
125 "in its data structures. This is most likely caused "
kono
parents:
diff changeset
126 "by an application bug. Aborting execution.\n");
kono
parents:
diff changeset
127 }
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 #ifdef WIN32
kono
parents:
diff changeset
130 COMMON_SYSDEP void __cilkrts_dbgprintf(const char *fmt,...)
kono
parents:
diff changeset
131 {
kono
parents:
diff changeset
132 char message[2048];
kono
parents:
diff changeset
133 va_list l;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 // Cilkscreen shouldn't watch this
kono
parents:
diff changeset
136 __cilkscreen_disable_checking();
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 va_start(l, fmt);
kono
parents:
diff changeset
139 _vsnprintf_s(message, 2048, _TRUNCATE, fmt, l);
kono
parents:
diff changeset
140 va_end(l);
kono
parents:
diff changeset
141 OutputDebugStringA (message);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 // Re-enable Cilkscreen
kono
parents:
diff changeset
144 __cilkscreen_enable_checking();
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146 #endif
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 __CILKRTS_END_EXTERN_C
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 /* End bug.cpp */