]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/runtime/go-runtime-error.c
libgo: don't use wc in gotest
[thirdparty/gcc.git] / libgo / runtime / go-runtime-error.c
CommitLineData
e440a328 1/* go-runtime-error.c -- Go runtime error.
2
3 Copyright 2010 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
6
3eb0217c 7#include "runtime.h"
e440a328 8
9/* The compiler generates calls to this function. This enum values
10 are known to the compiler and used by compiled code. Any change
11 here must be reflected in the compiler. */
12
13enum
14{
15 /* Slice index out of bounds: negative or larger than the length of
16 the slice. */
17 SLICE_INDEX_OUT_OF_BOUNDS = 0,
18
19 /* Array index out of bounds. */
20 ARRAY_INDEX_OUT_OF_BOUNDS = 1,
21
22 /* String index out of bounds. */
23 STRING_INDEX_OUT_OF_BOUNDS = 2,
24
25 /* Slice slice out of bounds: negative or larger than the length of
26 the slice or high bound less than low bound. */
27 SLICE_SLICE_OUT_OF_BOUNDS = 3,
28
29 /* Array slice out of bounds. */
30 ARRAY_SLICE_OUT_OF_BOUNDS = 4,
31
32 /* String slice out of bounds. */
33 STRING_SLICE_OUT_OF_BOUNDS = 5,
34
35 /* Dereference of nil pointer. This is used when there is a
36 dereference of a pointer to a very large struct or array, to
37 ensure that a gigantic array is not used a proxy to access random
38 memory locations. */
39 NIL_DEREFERENCE = 6,
40
41 /* Slice length or capacity out of bounds in make: negative or
42 overflow or length greater than capacity. */
43 MAKE_SLICE_OUT_OF_BOUNDS = 7,
44
45 /* Map capacity out of bounds in make: negative or overflow. */
46 MAKE_MAP_OUT_OF_BOUNDS = 8,
47
48 /* Channel capacity out of bounds in make: negative or overflow. */
29a2d1d8 49 MAKE_CHAN_OUT_OF_BOUNDS = 9,
50
51 /* Integer division by zero. */
789c8746 52 DIVISION_BY_ZERO = 10,
53
54 /* Go statement with nil function. */
55 GO_NIL = 11
e440a328 56};
57
86b4a2e6 58extern void __go_runtime_error (int32) __attribute__ ((noreturn));
e440a328 59
60void
1b1f2abf 61__go_runtime_error (int32 i)
e440a328 62{
b0751b12 63 struct funcfileline_return fileline;
64 bool in_runtime;
65
66 fileline = runtime_funcfileline ((uintptr) runtime_getcallerpc(), 0);
67 in_runtime = (fileline.retfn.len > 0
68 && (__builtin_strncmp ((const char *) fileline.retfn.str,
69 "runtime.", 8)
70 == 0));
71
e440a328 72 switch (i)
73 {
74 case SLICE_INDEX_OUT_OF_BOUNDS:
75 case ARRAY_INDEX_OUT_OF_BOUNDS:
76 case STRING_INDEX_OUT_OF_BOUNDS:
b0751b12 77 if (in_runtime)
78 runtime_throw ("index out of range");
3eb0217c 79 runtime_panicstring ("index out of range");
e440a328 80
81 case SLICE_SLICE_OUT_OF_BOUNDS:
82 case ARRAY_SLICE_OUT_OF_BOUNDS:
83 case STRING_SLICE_OUT_OF_BOUNDS:
b0751b12 84 if (in_runtime)
85 runtime_throw ("slice bounds out of range");
3eb0217c 86 runtime_panicstring ("slice bounds out of range");
e440a328 87
88 case NIL_DEREFERENCE:
3eb0217c 89 runtime_panicstring ("nil pointer dereference");
e440a328 90
91 case MAKE_SLICE_OUT_OF_BOUNDS:
3eb0217c 92 runtime_panicstring ("make slice len or cap out of range");
e440a328 93
94 case MAKE_MAP_OUT_OF_BOUNDS:
3eb0217c 95 runtime_panicstring ("make map len out of range");
e440a328 96
97 case MAKE_CHAN_OUT_OF_BOUNDS:
3eb0217c 98 runtime_panicstring ("make chan len out of range");
e440a328 99
29a2d1d8 100 case DIVISION_BY_ZERO:
101 runtime_panicstring ("integer divide by zero");
102
789c8746 103 case GO_NIL:
104 /* This one is a throw, rather than a panic. Set throwing to
105 not dump full stacks. */
106 runtime_g()->m->throwing = -1;
107 runtime_throw ("go of nil func value");
108
e440a328 109 default:
3eb0217c 110 runtime_panicstring ("unknown runtime error");
e440a328 111 }
112}