Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
69908ca8
Commit
69908ca8
authored
Jun 26, 2013
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiler: reject integer division by zero constant.
From-SVN: r200436
parent
9e216629
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
gcc/go/gofrontend/expressions.cc
+14
-0
gcc/testsuite/go.test/test/64bit.go
+23
-2
gcc/testsuite/go.test/test/fixedbugs/bug410.go
+1
-1
No files found.
gcc/go/gofrontend/expressions.cc
View file @
69908ca8
...
...
@@ -5848,6 +5848,20 @@ Binary_expression::do_check_types(Gogo*)
this
->
set_is_error
();
return
;
}
if
(
this
->
op_
==
OPERATOR_DIV
||
this
->
op_
==
OPERATOR_MOD
)
{
// Division by a zero integer constant is an error.
Numeric_constant
rconst
;
unsigned
long
rval
;
if
(
left_type
->
integer_type
()
!=
NULL
&&
this
->
right_
->
numeric_constant_value
(
&
rconst
)
&&
rconst
.
to_unsigned_long
(
&
rval
)
==
Numeric_constant
::
NC_UL_VALID
&&
rval
==
0
)
{
this
->
report_error
(
_
(
"integer division by zero"
));
return
;
}
}
}
else
{
...
...
gcc/testsuite/go.test/test/64bit.go
View file @
69908ca8
...
...
@@ -594,6 +594,19 @@ const binaryConstR = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or,
"}
\n
"
+
"
\n
"
const
binaryConstR0
=
"func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {
\n
"
+
" const b %v = %v;
\n
"
+
" const typ = `%s`;
\n
"
+
" if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
" if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }
\n
"
+
"}
\n
"
+
"
\n
"
const
shiftConstL
=
"func test%vShiftL%v(b uint64, left, right %v) {
\n
"
+
" const a %v = %v;
\n
"
+
" const typ = `%s`;
\n
"
+
...
...
@@ -621,12 +634,20 @@ const shiftConstR = "func test%vShiftR%v(a, left, right %v) {\n" +
func
constTests
()
{
for
i
,
a
:=
range
int64Values
{
fmt
.
Fprintf
(
bout
,
binaryConstL
,
"Int64"
,
i
,
"int64"
,
"int64"
,
a
,
"int64"
)
fmt
.
Fprintf
(
bout
,
binaryConstR
,
"Int64"
,
i
,
"int64"
,
"int64"
,
a
,
"int64"
)
if
a
.
hi
==
0
&&
a
.
lo
==
0
{
fmt
.
Fprintf
(
bout
,
binaryConstR0
,
"Int64"
,
i
,
"int64"
,
"int64"
,
a
,
"int64"
)
}
else
{
fmt
.
Fprintf
(
bout
,
binaryConstR
,
"Int64"
,
i
,
"int64"
,
"int64"
,
a
,
"int64"
)
}
fmt
.
Fprintf
(
bout
,
shiftConstL
,
"Int64"
,
i
,
"int64"
,
"int64"
,
a
,
"int64"
)
}
for
i
,
a
:=
range
uint64Values
{
fmt
.
Fprintf
(
bout
,
binaryConstL
,
"Uint64"
,
i
,
"uint64"
,
"uint64"
,
a
,
"uint64"
)
fmt
.
Fprintf
(
bout
,
binaryConstR
,
"Uint64"
,
i
,
"uint64"
,
"uint64"
,
a
,
"uint64"
)
if
a
.
hi
==
0
&&
a
.
lo
==
0
{
fmt
.
Fprintf
(
bout
,
binaryConstR0
,
"Uint64"
,
i
,
"uint64"
,
"uint64"
,
a
,
"uint64"
)
}
else
{
fmt
.
Fprintf
(
bout
,
binaryConstR
,
"Uint64"
,
i
,
"uint64"
,
"uint64"
,
a
,
"uint64"
)
}
fmt
.
Fprintf
(
bout
,
shiftConstL
,
"Uint64"
,
i
,
"uint64"
,
"uint64"
,
a
,
"uint64"
)
}
for
i
,
a
:=
range
shiftValues
{
...
...
gcc/testsuite/go.test/test/fixedbugs/bug410.go
View file @
69908ca8
...
...
@@ -18,7 +18,7 @@ func zzz () {
for
s
:=
range
arr
{
x
:=
make
([]
byte
,
10
)
for
i
:=
0
;
i
<
100
;
i
++
{
x
[
i
]
^=
k
[
i
-
arr
[
s
]
.
num
%
0
]
x
[
i
]
^=
k
[
i
-
arr
[
s
]
.
num
%
3
]
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment