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
3af76e5a
Commit
3af76e5a
authored
Aug 11, 2012
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiler: Reject type switch using non-interface type.
Fixes issue 16. From-SVN: r190310
parent
7380e6ef
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
24 deletions
+10
-24
gcc/go/gofrontend/statements.cc
+10
-24
No files found.
gcc/go/gofrontend/statements.cc
View file @
3af76e5a
...
@@ -4192,34 +4192,21 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
...
@@ -4192,34 +4192,21 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
?
this
->
var_
->
var_value
()
->
type
()
?
this
->
var_
->
var_value
()
->
type
()
:
this
->
expr_
->
type
());
:
this
->
expr_
->
type
());
if
(
val_type
->
interface_type
()
==
NULL
)
{
if
(
!
val_type
->
is_error
())
this
->
report_error
(
_
(
"cannot type switch on non-interface value"
));
return
Statement
::
make_error_statement
(
loc
);
}
// var descriptor_temp DESCRIPTOR_TYPE
// var descriptor_temp DESCRIPTOR_TYPE
Type
*
descriptor_type
=
Type
::
make_type_descriptor_ptr_type
();
Type
*
descriptor_type
=
Type
::
make_type_descriptor_ptr_type
();
Temporary_statement
*
descriptor_temp
=
Temporary_statement
*
descriptor_temp
=
Statement
::
make_temporary
(
descriptor_type
,
NULL
,
loc
);
Statement
::
make_temporary
(
descriptor_type
,
NULL
,
loc
);
b
->
add_statement
(
descriptor_temp
);
b
->
add_statement
(
descriptor_temp
);
if
(
val_type
->
interface_type
()
==
NULL
)
// descriptor_temp = ifacetype(val_temp) FIXME: This should be
{
// inlined.
// Doing a type switch on a non-interface type. Should we issue
// a warning for this case?
Expression
*
lhs
=
Expression
::
make_temporary_reference
(
descriptor_temp
,
loc
);
Expression
*
rhs
;
if
(
val_type
->
is_nil_type
())
rhs
=
Expression
::
make_nil
(
loc
);
else
{
if
(
val_type
->
is_abstract
())
val_type
=
val_type
->
make_non_abstract_type
();
rhs
=
Expression
::
make_type_descriptor
(
val_type
,
loc
);
}
Statement
*
s
=
Statement
::
make_assignment
(
lhs
,
rhs
,
loc
);
b
->
add_statement
(
s
);
}
else
{
// descriptor_temp = ifacetype(val_temp)
// FIXME: This should be inlined.
bool
is_empty
=
val_type
->
interface_type
()
->
is_empty
();
bool
is_empty
=
val_type
->
interface_type
()
->
is_empty
();
Expression
*
ref
;
Expression
*
ref
;
if
(
this
->
var_
==
NULL
)
if
(
this
->
var_
==
NULL
)
...
@@ -4235,12 +4222,11 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
...
@@ -4235,12 +4222,11 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
lhs
->
set_is_lvalue
();
lhs
->
set_is_lvalue
();
Statement
*
s
=
Statement
::
make_assignment
(
lhs
,
call
,
loc
);
Statement
*
s
=
Statement
::
make_assignment
(
lhs
,
call
,
loc
);
b
->
add_statement
(
s
);
b
->
add_statement
(
s
);
}
if
(
this
->
clauses_
!=
NULL
)
if
(
this
->
clauses_
!=
NULL
)
this
->
clauses_
->
lower
(
val_type
,
b
,
descriptor_temp
,
this
->
break_label
());
this
->
clauses_
->
lower
(
val_type
,
b
,
descriptor_temp
,
this
->
break_label
());
Statement
*
s
=
Statement
::
make_unnamed_label_statement
(
this
->
break_label_
);
s
=
Statement
::
make_unnamed_label_statement
(
this
->
break_label_
);
b
->
add_statement
(
s
);
b
->
add_statement
(
s
);
return
Statement
::
make_block_statement
(
b
,
loc
);
return
Statement
::
make_block_statement
(
b
,
loc
);
...
...
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