Add support for ARMv8-R architecture
[official-gcc.git] / libgo / runtime / go-runtime-error.c
blob4f563fc9ed5e37e8b1a059ac8d33dc7e63a54c4d
1 /* go-runtime-error.c -- Go runtime error.
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. */
7 #include "runtime.h"
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. */
13 enum
15 /* Slice index out of bounds: negative or larger than the length of
16 the slice. */
17 SLICE_INDEX_OUT_OF_BOUNDS = 0,
19 /* Array index out of bounds. */
20 ARRAY_INDEX_OUT_OF_BOUNDS = 1,
22 /* String index out of bounds. */
23 STRING_INDEX_OUT_OF_BOUNDS = 2,
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,
29 /* Array slice out of bounds. */
30 ARRAY_SLICE_OUT_OF_BOUNDS = 4,
32 /* String slice out of bounds. */
33 STRING_SLICE_OUT_OF_BOUNDS = 5,
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,
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,
45 /* Map capacity out of bounds in make: negative or overflow. */
46 MAKE_MAP_OUT_OF_BOUNDS = 8,
48 /* Channel capacity out of bounds in make: negative or overflow. */
49 MAKE_CHAN_OUT_OF_BOUNDS = 9,
51 /* Integer division by zero. */
52 DIVISION_BY_ZERO = 10,
54 /* Go statement with nil function. */
55 GO_NIL = 11
58 extern void __go_runtime_error () __attribute__ ((noreturn));
60 void
61 __go_runtime_error (int32 i)
63 switch (i)
65 case SLICE_INDEX_OUT_OF_BOUNDS:
66 case ARRAY_INDEX_OUT_OF_BOUNDS:
67 case STRING_INDEX_OUT_OF_BOUNDS:
68 runtime_panicstring ("index out of range");
70 case SLICE_SLICE_OUT_OF_BOUNDS:
71 case ARRAY_SLICE_OUT_OF_BOUNDS:
72 case STRING_SLICE_OUT_OF_BOUNDS:
73 runtime_panicstring ("slice bounds out of range");
75 case NIL_DEREFERENCE:
76 runtime_panicstring ("nil pointer dereference");
78 case MAKE_SLICE_OUT_OF_BOUNDS:
79 runtime_panicstring ("make slice len or cap out of range");
81 case MAKE_MAP_OUT_OF_BOUNDS:
82 runtime_panicstring ("make map len out of range");
84 case MAKE_CHAN_OUT_OF_BOUNDS:
85 runtime_panicstring ("make chan len out of range");
87 case DIVISION_BY_ZERO:
88 runtime_panicstring ("integer divide by zero");
90 case GO_NIL:
91 /* This one is a throw, rather than a panic. Set throwing to
92 not dump full stacks. */
93 runtime_g()->m->throwing = -1;
94 runtime_throw ("go of nil func value");
96 default:
97 runtime_panicstring ("unknown runtime error");