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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
38 deletions
+24
-38
gcc/go/gofrontend/statements.cc
+24
-38
No files found.
gcc/go/gofrontend/statements.cc
View file @
3af76e5a
...
@@ -4192,55 +4192,41 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
...
@@ -4192,55 +4192,41 @@ 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
bool
is_empty
=
val_type
->
interface_type
()
->
is_empty
();
// a warning for this case?
Expression
*
ref
;
Expression
*
lhs
=
Expression
::
make_temporary_reference
(
descriptor_temp
,
if
(
this
->
var_
==
NULL
)
loc
);
ref
=
this
->
expr_
;
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
else
{
ref
=
Expression
::
make_var_reference
(
this
->
var_
,
loc
);
// descriptor_temp = ifacetype(val_temp)
Expression
*
call
=
Runtime
::
make_call
((
is_empty
// FIXME: This should be inlined.
?
Runtime
::
EFACETYPE
bool
is_empty
=
val_type
->
interface_type
()
->
is_empty
();
:
Runtime
::
IFACETYPE
),
Expression
*
ref
;
loc
,
1
,
ref
);
if
(
this
->
var_
==
NULL
)
Temporary_reference_expression
*
lhs
=
ref
=
this
->
expr_
;
Expression
::
make_temporary_reference
(
descriptor_temp
,
loc
);
else
lhs
->
set_is_lvalue
();
ref
=
Expression
::
make_var_reference
(
this
->
var_
,
loc
);
Statement
*
s
=
Statement
::
make_assignment
(
lhs
,
call
,
loc
);
Expression
*
call
=
Runtime
::
make_call
((
is_empty
b
->
add_statement
(
s
);
?
Runtime
::
EFACETYPE
:
Runtime
::
IFACETYPE
),
loc
,
1
,
ref
);
Temporary_reference_expression
*
lhs
=
Expression
::
make_temporary_reference
(
descriptor_temp
,
loc
);
lhs
->
set_is_lvalue
();
Statement
*
s
=
Statement
::
make_assignment
(
lhs
,
call
,
loc
);
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