]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/runtime/go-runtime-error.c
c9ccf98736f7d142f049d66a6da6688bd3bdec10
[thirdparty/gcc.git] / libgo / runtime / go-runtime-error.c
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
7 #include "runtime.h"
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
13 enum
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 out of bounds in make: negative or overflow or length
42 greater than capacity. */
43 MAKE_SLICE_LEN_OUT_OF_BOUNDS = 7,
44
45 /* Slice capacity out of bounds in make: negative. */
46 MAKE_SLICE_CAP_OUT_OF_BOUNDS = 8,
47
48 /* Map capacity out of bounds in make: negative or overflow. */
49 MAKE_MAP_OUT_OF_BOUNDS = 9,
50
51 /* Channel capacity out of bounds in make: negative or overflow. */
52 MAKE_CHAN_OUT_OF_BOUNDS = 10,
53
54 /* Integer division by zero. */
55 DIVISION_BY_ZERO = 11,
56
57 /* Go statement with nil function. */
58 GO_NIL = 12
59 };
60
61 extern void __go_runtime_error (int32) __attribute__ ((noreturn));
62
63 void
64 __go_runtime_error (int32 i)
65 {
66 struct funcfileline_return fileline;
67 bool in_runtime;
68
69 fileline = runtime_funcfileline ((uintptr) runtime_getcallerpc()-1, 0);
70 in_runtime = (fileline.retfn.len > 0
71 && (__builtin_strncmp ((const char *) fileline.retfn.str,
72 "runtime.", 8)
73 == 0));
74
75 switch (i)
76 {
77 case SLICE_INDEX_OUT_OF_BOUNDS:
78 case ARRAY_INDEX_OUT_OF_BOUNDS:
79 case STRING_INDEX_OUT_OF_BOUNDS:
80 if (in_runtime)
81 runtime_throw ("index out of range");
82 runtime_panicstring ("index out of range");
83
84 case SLICE_SLICE_OUT_OF_BOUNDS:
85 case ARRAY_SLICE_OUT_OF_BOUNDS:
86 case STRING_SLICE_OUT_OF_BOUNDS:
87 if (in_runtime)
88 runtime_throw ("slice bounds out of range");
89 runtime_panicstring ("slice bounds out of range");
90
91 case NIL_DEREFERENCE:
92 runtime_panicstring ("nil pointer dereference");
93
94 case MAKE_SLICE_LEN_OUT_OF_BOUNDS:
95 runtime_panicstring ("make slice len out of range");
96
97 case MAKE_SLICE_CAP_OUT_OF_BOUNDS:
98 runtime_panicstring ("make slice cap out of range");
99
100 case MAKE_MAP_OUT_OF_BOUNDS:
101 runtime_panicstring ("make map len out of range");
102
103 case MAKE_CHAN_OUT_OF_BOUNDS:
104 runtime_panicstring ("make chan len out of range");
105
106 case DIVISION_BY_ZERO:
107 runtime_panicstring ("integer divide by zero");
108
109 case GO_NIL:
110 /* This one is a throw, rather than a panic. Set throwing to
111 not dump full stacks. */
112 runtime_g()->m->throwing = -1;
113 runtime_throw ("go of nil func value");
114
115 default:
116 runtime_panicstring ("unknown runtime error");
117 }
118 }